예제 #1
0
        protected override void Init(World world)
        {
            this.world = world;

            Body body1 = new StaticBody("Ground1", new Box(400.0f, 20.0f));
            body1.SetPosition(250.0f, 400);
            body1.Friction = 1;
            world.Add(body1);

            for (int y = 0; y < 5; y++)
            {
                int xbase = 250 - (y * 21);
                for (int x = 0; x < y + 1; x++)
                {
                    DynamicShape shape = new Box(40, 40);
                    if ((x == 1) && (y == 2))
                    {
                        shape = new Circle(19);
                    }
                    if ((x == 1) && (y == 4))
                    {
                        shape = new Circle(19);
                    }
                    if ((x == 3) && (y == 4))
                    {
                        shape = new Circle(19);
                    }
                    Body body2 = new Body("Mover1", shape, 100.0f);
                    body2.SetPosition(xbase + (x * 42), y * 45);
                    world.Add(body2);
                }
            }
        }
예제 #2
0
        /// <summary> Check if this circle Touches another
        /// 
        /// </summary>
        /// <param name="x">The x position of this circle
        /// </param>
        /// <param name="y">The y position of this circle
        /// </param>
        /// <param name="other">The other circle
        /// </param>
        /// <param name="ox">The other circle's x position
        /// </param>
        /// <param name="oy">The other circle's y position
        /// </param>
        /// <returns> True if they touch
        /// </returns>
        public virtual bool Touches(float x, float y, Circle other, float ox, float oy)
        {
            float totalRad2 = Radius + other.Radius;

            if (System.Math.Abs(ox - x) > totalRad2)
            {
                return false;
            }
            if (System.Math.Abs(oy - y) > totalRad2)
            {
                return false;
            }

            totalRad2 *= totalRad2;

            float dx = System.Math.Abs(ox - x);
            float dy = System.Math.Abs(oy - y);

            return totalRad2 >= ((dx * dx) + (dy * dy));
        }
예제 #3
0
        /// <summary> Creates a collider for a Circle and a Shape.
        /// The choice is based on the kind of Shape that is provided
        /// 
        /// </summary>
        /// <param name="shapeA">The circle to provide a collider for
        /// </param>
        /// <param name="shapeB">The shape to provide a collider for
        /// </param>
        /// <returns> a suitable collider
        /// </returns>
        /// <throws>  ColliderUnavailableException </throws>
        /// <summary> 	       This exception will be thrown if no suitable collider can be found.
        /// </summary>
        public virtual Collider CreateColliderFor(Circle shapeA, Shape shapeB)
        {
            if (shapeB is Circle)
            {
                return new CircleCircleCollider();
            }
            else if (shapeB is Box)
            {
                return new SwapCollider(new BoxCircleCollider());
            }
            else if (shapeB is Line)
            {
                return new SwapCollider(new LineCircleCollider());
            }
            else if (shapeB is Polygon)
            {
                return new SwapCollider(new PolygonCircleCollider());
            }

            throw new ColliderUnavailableException(shapeA, shapeB);
        }
예제 #4
0
        protected override void DrawCircleBody(Body body, Circle circle)
        {
            float x = body.GetPosition().X;
            float y = body.GetPosition().Y;
            float r = circle.Radius;
            float rot = body.Rotation;
            float xo = (float)(System.Math.Cos(rot) * r);
            float yo = (float)(System.Math.Sin(rot) * r);

            var circleSize = new Vector2f(circle.Radius * 2, circle.Radius * 2);

            UIElement e = body.UserData as UIElement;
            if (e == null)
            {
                e = new VisualCircle(circleSize, imagePath);
                canvas.Children.Add(e);
                body.UserData = e;
            }

            UpdateElementPosition(e, x, y, circleSize);
            ApplyRotationToElement(e, circle.Radius * 2, circle.Radius * 2, RadToDeg(body.Rotation));
        }
예제 #5
0
        protected virtual void DrawCircleBody(Body body, Circle circle)
        {
            float x = body.GetPosition().X;
            float y = body.GetPosition().Y;
            float r = circle.Radius;
            float rot = body.Rotation;
            float xo = (float)(System.Math.Cos(rot) * r);
            float yo = (float)(System.Math.Sin(rot) * r);

            Ellipse e = body.UserData as Ellipse;
            if (e == null)
            {
                e = new Ellipse();
                e.Stroke = new SolidColorBrush(Colors.Yellow);
                e.StrokeThickness = 1;
                e.Width = r * 2;
                e.Height = r * 2;
                canvas.Children.Add(e);
                body.UserData = e;
            }

            var circleSize = new Vector2f(circle.Radius*2, circle.Radius*2);
            UpdateElementPosition(e, Convert.ToInt32(x), Convert.ToInt32(y), circleSize);
        }