Esempio n. 1
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = Vector2.Zero;

            _border = new Border(World, Lines, Framework.GraphicsDevice);

            _rectangle          = BodyFactory.CreateRectangle(World, 5f, 5f, 1f);
            _rectangle.BodyType = BodyType.Dynamic;

            SetUserAgent(_rectangle, 100f, 100f);

            // create sprite based on body
            _rectangleSprite = new Sprite(ContentWrapper.TextureFromShape(_rectangle.FixtureList[0].Shape, "Square", ContentWrapper.Blue, ContentWrapper.Gold, ContentWrapper.Black, 1f));
        }
Esempio n. 2
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, 20f);

            Vector2 position    = new Vector2(-15f, -8f);
            float   restitution = 0f;

            for (int i = 0; i < 6; ++i)
            {
                _circle[i]             = BodyFactory.CreateCircle(World, 1.5f, 1f, position);
                _circle[i].BodyType    = BodyType.Dynamic;
                _circle[i].Restitution = restitution;
                position.X            += 6f;
                restitution           += 0.2f;
            }

            // create sprite based on body
            _circleSprite = new Sprite(ContentWrapper.TextureFromShape(_circle[0].FixtureList[0].Shape, "Square", ContentWrapper.Green, ContentWrapper.Lime, ContentWrapper.Black, 1f));
        }
Esempio n. 3
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, 20f);

            _ragdoll = new Ragdoll(World, new Vector2(-20f, -10f));

            _obstacles = new Body[9];
            Vector2 stairStart = new Vector2(-23f, 0f);
            Vector2 stairDelta = new Vector2(2.5f, 1.65f);

            for (int i = 0; i < 9; i++)
            {
                _obstacles[i]          = BodyFactory.CreateRectangle(World, 5f, 1.5f, 1f, stairStart + stairDelta * i);
                _obstacles[i].BodyType = BodyType.Static;
            }

            // create sprite based on body
            _obstacle = new Sprite(ContentWrapper.TextureFromShape(_obstacles[0].FixtureList[0].Shape, "Stripe", ContentWrapper.Red, ContentWrapper.Black, ContentWrapper.Black, 1.5f));

            SetUserAgent(_ragdoll.Body, 1000f, 400f);
        }
Esempio n. 4
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, -20f);

            _border = new Border(World, LineBatch, Framework.GraphicsDevice);

            Vector2 position    = new Vector2(-15f, 8f);
            float   restitution = 0f;

            for (int i = 0; i < 6; ++i)
            {
                _circle[i]          = World.CreateCircle(1.5f, 1f, position);
                _circle[i].BodyType = BodyType.Dynamic;
                _circle[i].SetRestitution(restitution);
                position.X  += 6f;
                restitution += 0.2f;
            }

            // create sprite based on body
            _circleSprite = new Sprite(ContentWrapper.TextureFromShape(_circle[0].FixtureList[0].Shape, "Square", ContentWrapper.Green, ContentWrapper.Lime, ContentWrapper.Black, 1f, 24f));
        }
Esempio n. 5
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, 10f);

            HasCursor           = false;
            EnableCameraControl = true;

            _hzFront  = 8.5f;
            _hzBack   = 5.0f;
            _zeta     = 0.85f;
            _maxSpeed = 50.0f;

            // terrain
            _ground = BodyFactory.CreateBody(World);
            {
                Vertices terrain = new Vertices();
                terrain.Add(new Vector2(-20f, -5f));
                terrain.Add(new Vector2(-20f, 0f));
                terrain.Add(new Vector2(20f, 0f));
                terrain.Add(new Vector2(25f, -0.25f));
                terrain.Add(new Vector2(30f, -1f));
                terrain.Add(new Vector2(35f, -4f));
                terrain.Add(new Vector2(40f, 0f));
                terrain.Add(new Vector2(45f, 0f));
                terrain.Add(new Vector2(50f, 1f));
                terrain.Add(new Vector2(55f, 2f));
                terrain.Add(new Vector2(60f, 2f));
                terrain.Add(new Vector2(65f, 1.25f));
                terrain.Add(new Vector2(70f, 0f));
                terrain.Add(new Vector2(75f, -0.3f));
                terrain.Add(new Vector2(80f, -1.5f));
                terrain.Add(new Vector2(85f, -3.5f));
                terrain.Add(new Vector2(90f, 0f));
                terrain.Add(new Vector2(95f, 0.5f));
                terrain.Add(new Vector2(100f, 1f));
                terrain.Add(new Vector2(105f, 2f));
                terrain.Add(new Vector2(110f, 2.5f));
                terrain.Add(new Vector2(115f, 1.3f));
                terrain.Add(new Vector2(120f, 0f));
                terrain.Add(new Vector2(160f, 0f));
                terrain.Add(new Vector2(159f, 10f));
                terrain.Add(new Vector2(201f, 10f));
                terrain.Add(new Vector2(200f, 0f));
                terrain.Add(new Vector2(240f, 0f));
                terrain.Add(new Vector2(250f, -5f));
                terrain.Add(new Vector2(250f, 10f));
                terrain.Add(new Vector2(270f, 10f));
                terrain.Add(new Vector2(270f, 0));
                terrain.Add(new Vector2(310f, 0));
                terrain.Add(new Vector2(310f, -5));

                for (int i = 0; i < terrain.Count - 1; ++i)
                {
                    FixtureFactory.AttachEdge(terrain[i], terrain[i + 1], _ground);
                }

                _ground.Friction = 0.6f;
            }

            // teeter board
            {
                _board          = BodyFactory.CreateBody(World);
                _board.BodyType = BodyType.Dynamic;
                _board.Position = new Vector2(140.0f, -1.0f);

                PolygonShape box = new PolygonShape(1f);
                box.Vertices = PolygonUtils.CreateRectangle(10.0f, 0.25f);
                _teeter      = new Sprite(ContentWrapper.TextureFromShape(box, "Stripe", ContentWrapper.Gold, ContentWrapper.Black, ContentWrapper.Black, 1f));

                _board.CreateFixture(box);

                RevoluteJoint teeterAxis = JointFactory.CreateRevoluteJoint(World, _ground, _board, Vector2.Zero);
                teeterAxis.LowerLimit   = -8.0f * MathConstants.Pi / 180.0f;
                teeterAxis.UpperLimit   = 8.0f * MathConstants.Pi / 180.0f;
                teeterAxis.LimitEnabled = true;

                _board.ApplyAngularImpulse(-100.0f);
            }

            // bridge
            {
                _bridgeSegments = new List <Body>();

                const int    segmentCount = 20;
                PolygonShape shape        = new PolygonShape(1f);
                shape.Vertices = PolygonUtils.CreateRectangle(1.0f, 0.125f);

                _bridge = new Sprite(ContentWrapper.TextureFromShape(shape, ContentWrapper.Gold, ContentWrapper.Black));

                Body prevBody = _ground;
                for (int i = 0; i < segmentCount; ++i)
                {
                    Body body = BodyFactory.CreateBody(World);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(161f + 2f * i, 0.125f);
                    Fixture fix = body.CreateFixture(shape);
                    fix.Friction = 0.6f;
                    JointFactory.CreateRevoluteJoint(World, prevBody, body, -Vector2.UnitX);

                    prevBody = body;
                    _bridgeSegments.Add(body);
                }
                JointFactory.CreateRevoluteJoint(World, _ground, prevBody, Vector2.UnitX);
            }

            // boxes
            {
                _boxes = new List <Body>();
                PolygonShape box = new PolygonShape(1f);
                box.Vertices = PolygonUtils.CreateRectangle(0.5f, 0.5f);
                _box         = new Sprite(ContentWrapper.TextureFromShape(box, "Square", ContentWrapper.Sky, ContentWrapper.Sunset, ContentWrapper.Black, 1f));

                Body body = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, -0.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, -1.5f);
                body.CreateFixture(box);
                _boxes.Add(body);

                body          = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(220f, -2.5f);
                body.CreateFixture(box);
                _boxes.Add(body);
            }

            // car
            {
                Vertices vertices = new Vertices(8);
                vertices.Add(new Vector2(-2.5f, 0.08f));
                vertices.Add(new Vector2(-2.375f, -0.46f));
                vertices.Add(new Vector2(-0.58f, -0.92f));
                vertices.Add(new Vector2(0.46f, -0.92f));
                vertices.Add(new Vector2(2.5f, -0.17f));
                vertices.Add(new Vector2(2.5f, 0.205f));
                vertices.Add(new Vector2(2.3f, 0.33f));
                vertices.Add(new Vector2(-2.25f, 0.35f));

                PolygonShape chassis = new PolygonShape(vertices, 2f);

                _car          = BodyFactory.CreateBody(World);
                _car.BodyType = BodyType.Dynamic;
                _car.Position = new Vector2(0.0f, -1.0f);
                _car.CreateFixture(chassis);

                _wheelBack          = BodyFactory.CreateBody(World);
                _wheelBack.BodyType = BodyType.Dynamic;
                _wheelBack.Position = new Vector2(-1.709f, -0.78f);
                Fixture fix = _wheelBack.CreateFixture(new CircleShape(0.5f, 0.8f));
                fix.Friction = 0.9f;

                _wheelFront          = BodyFactory.CreateBody(World);
                _wheelFront.BodyType = BodyType.Dynamic;
                _wheelFront.Position = new Vector2(1.54f, -0.8f);
                _wheelFront.CreateFixture(new CircleShape(0.5f, 1f));

                Vector2 axis = new Vector2(0.0f, -1.2f);
                _springBack                = new WheelJoint(_car, _wheelBack, _wheelBack.Position, axis, true);
                _springBack.MotorSpeed     = 0.0f;
                _springBack.MaxMotorTorque = 20.0f;
                _springBack.MotorEnabled   = true;
                _springBack.Frequency      = _hzBack;
                _springBack.DampingRatio   = _zeta;
                World.AddJoint(_springBack);

                _springFront                = new WheelJoint(_car, _wheelFront, _wheelFront.Position, axis, true);
                _springFront.MotorSpeed     = 0.0f;
                _springFront.MaxMotorTorque = 10.0f;
                _springFront.MotorEnabled   = false;
                _springFront.Frequency      = _hzFront;
                _springFront.DampingRatio   = _zeta;
                World.AddJoint(_springFront);

                // GFX
                _carBody = new Sprite(ContentWrapper.GetTexture("Car"), ContentWrapper.CalculateOrigin(_car));
                _wheel   = new Sprite(ContentWrapper.GetTexture("Wheel"));
            }

            Camera.MinRotation = -0.05f;
            Camera.MaxRotation = 0.05f;

            Camera.TrackingBody   = _car;
            Camera.EnableTracking = true;
        }
Esempio n. 6
0
        public TheoJansenWalker(World world, Vector2 position)
        {
            _position   = position;
            _motorSpeed = 2.0f;
            _motorOn    = true;

            _leftShoulders = new Body[3];
            _leftLegs      = new Body[3];

            _rightShoulders = new Body[3];
            _rightLegs      = new Body[3];

            Vector2 pivot = new Vector2(0f, 0.8f);

            // Chassis
            PolygonShape box = new PolygonShape(1f);

            box.Vertices = PolygonTools.CreateRectangle(2.5f, 1.0f);
            _body        = new Sprite(ContentWrapper.TextureFromShape(box, _walkerColors[0], ContentWrapper.Black, 24f));

            _chassis          = world.CreateBody();
            _chassis.BodyType = BodyType.Dynamic;
            _chassis.Position = pivot + _position;

            Fixture bodyFixture = _chassis.CreateFixture(box);

            bodyFixture.CollisionGroup = -1;

            // Wheel
            CircleShape circle = new CircleShape(1.6f, 1f);

            _engine = new Sprite(ContentWrapper.TextureFromShape(circle, "Stripe", _walkerColors[1] * 0.6f, _walkerColors[2] * 0.8f, ContentWrapper.Black, 3f, 24f));

            _wheel          = world.CreateBody();
            _wheel.BodyType = BodyType.Dynamic;
            _wheel.Position = pivot + _position;

            Fixture wheelFixture = _wheel.CreateFixture(circle);

            wheelFixture.CollisionGroup = -1;

            // Physics
            _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true);
            _motorJoint.CollideConnected = false;
            _motorJoint.MotorSpeed       = _motorSpeed;
            _motorJoint.MaxMotorTorque   = 400f;
            _motorJoint.MotorEnabled     = _motorOn;
            world.Add(_motorJoint);

            Vector2 wheelAnchor = pivot + new Vector2(0f, -0.8f);

            CreateLeg(world, -1f, wheelAnchor, out _leftShoulders[0], out _leftLegs[0]);
            CreateLeg(world, 1f, wheelAnchor, out _rightShoulders[0], out _rightLegs[0]);

            _wheel.SetTransform(_wheel.Position, 120f * MathHelper.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, out _leftShoulders[1], out _leftLegs[1]);
            CreateLeg(world, 1f, wheelAnchor, out _rightShoulders[1], out _rightLegs[1]);

            _wheel.SetTransform(_wheel.Position, -120f * MathHelper.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, out _leftShoulders[2], out _leftLegs[2]);
            CreateLeg(world, 1f, wheelAnchor, out _rightShoulders[2], out _rightLegs[2]);

            CreateLegTextures();
        }
Esempio n. 7
0
        public TheoJansenWalker(World world, Vector2 position)
        {
            _position   = position;
            _motorSpeed = 2.0f;
            _motorOn    = true;

            _leftShoulders = new Body[3];
            _leftLegs      = new Body[3];

            _rightShoulders = new Body[3];
            _rightLegs      = new Body[3];

            Vector2 pivot = new Vector2(0f, -0.8f);

            // Chassis
            PolygonShape box = new PolygonShape(1f);

            box.Vertices = PolygonUtils.CreateRectangle(2.5f, 1.0f);
            _body        = new Sprite(ContentWrapper.TextureFromShape(box, _walkerColors[0], ContentWrapper.Black));

            _chassis          = BodyFactory.CreateBody(world);
            _chassis.BodyType = BodyType.Dynamic;
            _chassis.Position = pivot + _position;

            Fixture bodyFixture = _chassis.CreateFixture(box);

            bodyFixture.CollisionGroup = -1;

            // Wheel
            CircleShape circle = new CircleShape(1.6f, 1f);

            _engine = new Sprite(ContentWrapper.TextureFromShape(circle, "Stripe", _walkerColors[1] * 0.6f, _walkerColors[2] * 0.8f, ContentWrapper.Black, 3f));

            _wheel          = BodyFactory.CreateBody(world);
            _wheel.BodyType = BodyType.Dynamic;
            _wheel.Position = pivot + _position;

            Fixture wheelFixture = _wheel.CreateFixture(circle);

            wheelFixture.CollisionGroup = -1;

            // Physics
            _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true);
            _motorJoint.CollideConnected = false;
            _motorJoint.MotorSpeed       = _motorSpeed;
            _motorJoint.MaxMotorTorque   = 400f;
            _motorJoint.MotorEnabled     = _motorOn;
            world.AddJoint(_motorJoint);

            Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f);

            CreateLeg(world, -1f, wheelAnchor, 0);
            CreateLeg(world, 1f, wheelAnchor, 0);

            _wheel.SetTransform(_wheel.Position, 120f * MathConstants.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 1);
            CreateLeg(world, 1f, wheelAnchor, 1);

            _wheel.SetTransform(_wheel.Position, -120f * MathConstants.Pi / 180f);
            CreateLeg(world, -1f, wheelAnchor, 2);
            CreateLeg(world, 1f, wheelAnchor, 2);

            // GFX
            Vector2[] points =
            {
                new Vector2(-5.4f,  6.1f),
                new Vector2(-7.2f,  1.2f),
                new Vector2(-4.3f,  1.9f),
                new Vector2(-2.9f, -0.7f),
                new Vector2(0.6f, -2.9f)
            };

            _leftShoulder        = new Sprite(ContentWrapper.PolygonTexture(new[] { Vector2.Zero, points[3], points[4] }, Color.White * 0.6f, ContentWrapper.Black));
            _leftShoulder.Origin = ContentWrapper.CalculateOrigin(_leftShoulders[0]);

            _leftLeg        = new Sprite(ContentWrapper.PolygonTexture(new[] { points[0], points[1], points[2] }, Color.White * 0.6f, ContentWrapper.Black));
            _leftLeg.Origin = ContentWrapper.CalculateOrigin(_leftLegs[0]);

            for (int i = 0; i < points.Length; i++)
            {
                points[i].X *= -1f;
            }

            _rightShoulder        = new Sprite(ContentWrapper.PolygonTexture(new[] { Vector2.Zero, points[4], points[3] }, Color.White * 0.6f, ContentWrapper.Black));
            _rightShoulder.Origin = ContentWrapper.CalculateOrigin(_rightShoulders[0]);

            _rightLeg        = new Sprite(ContentWrapper.PolygonTexture(new[] { points[0], points[2], points[1] }, Color.White * 0.6f, ContentWrapper.Black));
            _rightLeg.Origin = ContentWrapper.CalculateOrigin(_rightLegs[0]);
        }