Exemple #1
0
        public ExampleOne()
            : base(800, 450, GraphicsMode.Default, "Farseer Physics - Example One")
        {
            GL.ClearColor(Color4.White);

            shapeRenderer = new ShapeRenderer(800, 450);

            world = new World(new Vector2(0f, 9.8f));

            //Create two rectangles, one that doesn't move and acts like a platform, and another that's a dynamic box

            Vector2 size = new Vector2(50f, 50f);

            body01          = BodyFactory.CreateRectangle(world, size.X * pixelToUnit, size.Y * pixelToUnit, 1f);
            body01.BodyType = BodyType.Dynamic;
            body01.Position = new Vector2(400f, 0f) * pixelToUnit;

            body01Shape = ShapeConstructor.ConstructShapeFromBody(body01);

            size            = new Vector2(800f, 50f);
            body02          = BodyFactory.CreateRectangle(world, size.X * pixelToUnit, size.Y * pixelToUnit, 1f);
            body02.BodyType = BodyType.Kinematic;
            body02.Position = new Vector2(400f, 225f) * pixelToUnit;
            body02.Rotation = MathHelper.PiOver6;

            body02Shape = ShapeConstructor.ConstructShapeFromBody(body02);
        }
Exemple #2
0
        public ExampleTwo()
            : base(800, 450, GraphicsMode.Default, "Farseer Physics - Example Two")
        {
            GL.ClearColor(Color4.White);

            shapeRenderer = new ShapeRenderer(800, 450);
            lastState     = GamePad.GetState(0);
            rng           = new Random();

            world = new World(new Vector2(0f, 9.8f));
            boxes = new List <Body>();

            ball               = BodyFactory.CreateCapsule(world, 48f * pixelToUnit, 12f * pixelToUnit, 1f, new Vector2(400f, 225f));
            ball               = BodyFactory.CreateCircle(world, 24f * pixelToUnit, 1f);
            ball.BodyType      = BodyType.Dynamic;
            ball.Position      = new Vector2(400f, 225f) * pixelToUnit;
            ball.FixedRotation = true;

            rocketShape = ShapeConstructor.ConstructShapeFromBody(ball);

            platform          = BodyFactory.CreateRectangle(world, 800f * pixelToUnit, 800f * pixelToUnit, 1f);
            platform.BodyType = BodyType.Static;
            platform.Position = new Vector2(400f, 825f) * pixelToUnit;
        }