コード例 #1
0
        private void CreateLegTextures()
        {
            Vector2 p1 = new Vector2(-5.4f, -6.1f);
            Vector2 p2 = new Vector2(-7.2f, -1.2f);
            Vector2 p3 = new Vector2(-4.3f, -1.9f);
            Vector2 p4 = Vector2.Zero;
            Vector2 p5 = new Vector2(-2.9f, 0.7f);
            Vector2 p6 = new Vector2(0.6f, 2.9f);

            _leftShoulder        = new Sprite(ContentWrapper.PolygonTexture(new[] { p4, p5, p6 }, Color.White * 0.6f, ContentWrapper.Black, 24f));
            _leftShoulder.Origin = ContentWrapper.CalculateOrigin(_leftShoulders[0], 24f);

            _leftLeg        = new Sprite(ContentWrapper.PolygonTexture(new[] { p1, p3, p2 }, Color.White * 0.6f, ContentWrapper.Black, 24f));
            _leftLeg.Origin = ContentWrapper.CalculateOrigin(_leftLegs[0], 24f);

            p1.X *= -1f;
            p2.X *= -1f;
            p3.X *= -1f;
            p5.X *= -1f;
            p6.X *= -1f;

            _rightShoulder        = new Sprite(ContentWrapper.PolygonTexture(new[] { p4, p6, p5 }, Color.White * 0.6f, ContentWrapper.Black, 24f));
            _rightShoulder.Origin = ContentWrapper.CalculateOrigin(_rightShoulders[0], 24f);

            _rightLeg        = new Sprite(ContentWrapper.PolygonTexture(new[] { p1, p2, p3 }, Color.White * 0.6f, ContentWrapper.Black, 24f));
            _rightLeg.Origin = ContentWrapper.CalculateOrigin(_rightLegs[0], 24f);
        }
コード例 #2
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = Vector2.Zero;

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

            List <Vertices> tracedObject = Framework.Content.Load <List <Vertices> >("Pipeline/Object");

            //scale the vertices from graphics space to sim space
            Vector2 vertScale = new Vector2(1f / 24f);
            AABB    aabb      = new AABB();

            foreach (Vertices vertices in tracedObject)
            {
                vertices.Scale(new Vector2(1f, -1f));
                vertices.Translate(new Vector2(0f, 0f));

                var vaabb = vertices.GetAABB();
                aabb.Combine(ref vaabb);
            }
            _polygonSize = new Vector2(aabb.Width, aabb.Height);

            // Create a single body with multiple fixtures
            _compound = World.CreateCompoundPolygon(tracedObject, 1f, Vector2.Zero, 0, BodyType.Dynamic);

            SetUserAgent(_compound, 200f, 200f);
            _objectSprite = new Sprite(ContentWrapper.GetTexture("Logo"), ContentWrapper.CalculateOrigin(_compound, 24f));
        }
コード例 #3
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = Vector2.Zero;

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

            List <Vertices> tracedObject = Framework.Content.Load <List <Vertices> >("Pipeline/Object");

            // Create a single body with multiple fixtures
            _compound = BodyFactory.CreateCompoundPolygon(World, tracedObject, 1f, Vector2.Zero, 0, BodyType.Dynamic);

            SetUserAgent(_compound, 200f, 200f);
            _objectSprite = new Sprite(ContentWrapper.GetTexture("Logo"), ContentWrapper.CalculateOrigin(_compound));
        }
コード例 #4
0
        public override void LoadContent()
        {
            base.LoadContent();

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

            _loadedVertices = Framework.Content.Load <VerticesContainer>("Pipeline/Body");

            _heartBody = Create(_loadedVertices["Heart"]);
            _heart     = new Sprite(ContentWrapper.GetTexture("Heart"), ContentWrapper.CalculateOrigin(_heartBody));

            _clubBody = Create(_loadedVertices["Club"]);
            _club     = new Sprite(ContentWrapper.GetTexture("Club"), ContentWrapper.CalculateOrigin(_clubBody));

            _spadeBody = Create(_loadedVertices["Spade"]);
            _spade     = new Sprite(ContentWrapper.GetTexture("Spade"), ContentWrapper.CalculateOrigin(_spadeBody));

            _diamondBody = Create(_loadedVertices["Diamond"]);
            _diamond     = new Sprite(ContentWrapper.GetTexture("Diamond"), ContentWrapper.CalculateOrigin(_diamondBody));
        }
コード例 #5
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, 10f);
            _border       = new Border(World, Lines, Framework.GraphicsDevice);

            _body = Framework.Content.Load <BodyContainer>("Pipeline/Body");

            _heartBody = _body["Heart"].Create(World);
            _heart     = new Sprite(ContentWrapper.GetTexture("Heart"), ContentWrapper.CalculateOrigin(_heartBody));

            _clubBody = _body["Club"].Create(World);
            _club     = new Sprite(ContentWrapper.GetTexture("Club"), ContentWrapper.CalculateOrigin(_clubBody));

            _spadeBody = _body["Spade"].Create(World);
            _spade     = new Sprite(ContentWrapper.GetTexture("Spade"), ContentWrapper.CalculateOrigin(_spadeBody));

            _diamondBody = _body["Diamond"].Create(World);
            _diamond     = new Sprite(ContentWrapper.GetTexture("Diamond"), ContentWrapper.CalculateOrigin(_diamondBody));
        }
コード例 #6
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0f, -10f);
            _border       = new Border(World, LineBatch, Framework.GraphicsDevice);

            _BodyContainer = Framework.Content.Load <BodyContainer>("Pipeline/Body");

            _heart   = new Sprite(ContentWrapper.GetTexture("Heart"));
            _club    = new Sprite(ContentWrapper.GetTexture("Club"));
            _spade   = new Sprite(ContentWrapper.GetTexture("Spade"));
            _diamond = new Sprite(ContentWrapper.GetTexture("Diamond"));

            if (!_flipped)
            {
                foreach (var b in _BodyContainer.Values)
                {
                    foreach (var f in b.Fixtures)
                    {
                        var shape = (PolygonShape)f.Shape;
                        shape.Vertices.Scale(new Vector2(1f, -1f)); // flip Vertices
                    }
                }

                _flipped = true;
            }

            _heartBody   = _BodyContainer["Heart"].Create(World);
            _clubBody    = _BodyContainer["Club"].Create(World);
            _spadeBody   = _BodyContainer["Spade"].Create(World);
            _diamondBody = _BodyContainer["Diamond"].Create(World);

            _heart.Origin   = ContentWrapper.CalculateOrigin(_heartBody, 24f);
            _club.Origin    = ContentWrapper.CalculateOrigin(_clubBody, 24f);
            _spade.Origin   = ContentWrapper.CalculateOrigin(_spadeBody, 24f);
            _diamond.Origin = ContentWrapper.CalculateOrigin(_diamondBody, 24f);
        }
コード例 #7
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;
        }
コード例 #8
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]);
        }