Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary> Creates a collider for a Box and a Shape.
        /// The choice is based on the kind of Shape that is provided
        /// 
        /// </summary>
        /// <param name="shapeA">The box 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(Box shapeA, Shape shapeB)
        {
            if (shapeB is Circle)
            {
                return new BoxCircleCollider();
            }
            else if (shapeB is Box)
            {
                return new BoxBoxCollider();
            }
            else if (shapeB is Line)
            {
                return new SwapCollider(new LineBoxCollider());
            }
            else if (shapeB is Polygon)
            {
                return new SwapCollider(new PolygonBoxCollider());
            }

            throw new ColliderUnavailableException(shapeA, shapeB);
        }
Ejemplo n.º 3
0
        protected override void DrawBoxBody(Body body, Box box)
        {
            FrameworkElement e = body.UserData as FrameworkElement;
            if (e == null)
            {
                e = new VisualBox(box.Size, imagePath);

                canvas.Children.Add(e);
                body.UserData = e;
            }
            ROVector2f pos = body.GetPosition();
            if(Single.IsNaN(pos.X) || Single.IsNaN(pos.Y)) return;
            UpdateElementPosition(e, Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), box.Size);
            ApplyRotationToElement(e,box.Size.X,box.Size.Y,RadToDeg(body.Rotation));
        }
Ejemplo n.º 4
0
        protected virtual void DrawBoxBody(Body body, Box box)
        {
            System.Windows.Shapes.Polygon poly = body.UserData as System.Windows.Shapes.Polygon;
            ROVector2f[] points = box.GetPoints(body.GetPosition(), body.Rotation);
            if (poly == null)
            {
                poly = new System.Windows.Shapes.Polygon();

                poly.StrokeThickness = 1;
                poly.Stroke = new SolidColorBrush(Colors.Yellow);

                PointCollection pts = new PointCollection();
                pts.Add(new Point(points[0].X, points[0].Y));
                pts.Add(new Point(points[1].X, points[1].Y));
                pts.Add(new Point(points[2].X, points[2].Y));
                pts.Add(new Point(points[3].X, points[3].Y));
                poly.Points = pts;
                canvas.Children.Add(poly);
                body.UserData = poly;
            }
            else
            {
                PointCollection pts = new PointCollection();
                pts.Add(new Point(points[0].X, points[0].Y));
                pts.Add(new Point(points[1].X, points[1].Y));
                pts.Add(new Point(points[2].X, points[2].Y));
                pts.Add(new Point(points[3].X, points[3].Y));
                poly.Points = pts;
            }
        }