Example #1
0
        public override void LoadContent()
        {
            bodyA = BodyFactory.Instance.CreateRectangleBody(100, 25, 5);
            bodyB = BodyFactory.Instance.CreateRectangleBody(100, 25, 5);

            bodyA.Position = new Vector2(250, 300);
            bodyB.Position = new Vector2(350, 300);

            geomA = GeomFactory.Instance.CreateRectangleGeom(bodyA, 100, 25);
            geomB = GeomFactory.Instance.CreateRectangleGeom(bodyB, 100, 25);

            weldJoint = new WeldJoint(bodyA, bodyB, new Vector2(300, 300));
            weldJoint.Broke += weldJoint_Broke;
            weldJoint.Breakpoint = 5.0f;

            PhysicsSimulator.Add(bodyA);
            PhysicsSimulator.Add(bodyB);
            PhysicsSimulator.Add(geomA);
            PhysicsSimulator.Add(geomB);
            PhysicsSimulator.Add(weldJoint);

            brush = new PolygonBrush(Vertices.CreateRectangle(100, 25), Color.White, Color.Black, 2.0f, 0.5f);

            brush.Load(ScreenManager.GraphicsDevice);

            bodyC = BodyFactory.Instance.CreatePolygonBody(Vertices.CreateGear(50, 20, .50f, 10), 10);
            bodyC.Position = new Vector2(500, 200);

            geomC = GeomFactory.Instance.CreatePolygonGeom(bodyC, Vertices.CreateGear(50, 20, .50f, 10), 1.5f);

            bodyD = BodyFactory.Instance.CreatePolygonBody(Vertices.CreateGear(50, 20, .50f, 10), 10);
            bodyD.Position = new Vector2(613, 200);

            geomD = GeomFactory.Instance.CreatePolygonGeom(bodyD, Vertices.CreateGear(50, 20, .50f, 10), 1.5f);

            geomC.CollisionGroup = 2;
            geomD.CollisionGroup = 3;
            geomC.FrictionCoefficient = 0f;
            geomD.FrictionCoefficient = 0f;

            PhysicsSimulator.Add(bodyC);
            PhysicsSimulator.Add(geomC);
            PhysicsSimulator.Add(bodyD);
            PhysicsSimulator.Add(geomD);

            gearBrushA = new PolygonBrush(Vertices.CreateGear(50, 20, .50f, 10), Color.White, Color.Black, 0.5f, 0.5f);

            gearBrushA.Load(ScreenManager.GraphicsDevice);

            gearBrushB = new PolygonBrush(Vertices.CreateGear(50, 20, .50f, 10), Color.White, Color.Black, 0.5f, 0.5f);

            gearBrushB.Load(ScreenManager.GraphicsDevice);

            revJointA = JointFactory.Instance.CreateFixedRevoluteJoint(bodyC, bodyC.Position);
            revJointB = JointFactory.Instance.CreateFixedRevoluteJoint(bodyD, bodyD.Position);

            PhysicsSimulator.Add(revJointA);
            PhysicsSimulator.Add(revJointB);

            table = new List<Table>();

            table.Add(new Table(new Vector2(200, 450), 200, 50));

            table[0].Load(PhysicsSimulator, ScreenManager.GraphicsDevice);

            base.LoadContent();
        }
Example #2
0
        public void Load(PhysicsSimulator physicsSimulator, GraphicsDevice device)
        {
            Random rand = new Random();

            physicsSimulator.Add(_topBody);
            physicsSimulator.Add(_rightLegBody);
            physicsSimulator.Add(_leftLegBody);
            physicsSimulator.Add(_topGeom);
            physicsSimulator.Add(_rightLegGeom);
            physicsSimulator.Add(_leftLegGeom);

            _leftWeldJoint = new WeldJoint(_leftLegBody, _topBody, _leftLegBody.Position - new Vector2(-5, _height / 2));
            _leftWeldJoint.Breakpoint = (float)rand.NextDouble() * 3f + 1f;
            _leftWeldJoint.Broke += _leftWeldJoint_Broke;
            physicsSimulator.Add(_leftWeldJoint);

            _rightWeldJoint = new WeldJoint(_rightLegBody, _topBody, _rightLegBody.Position - new Vector2(5, _height / 2));
            _rightWeldJoint.Breakpoint = (float)rand.NextDouble() * 3f + 1f;
            _rightWeldJoint.Broke += _rightWeldJoint_Broke;
            physicsSimulator.Add(_rightWeldJoint);

            _topBrush = new PolygonBrush(_topGeom.LocalVertices, Color.BurlyWood, Color.Black, 1.0f, 0.5f);
            _leftBrush = new PolygonBrush(_leftLegGeom.LocalVertices, Color.BurlyWood, Color.Black, 1.0f, 0.5f);
            _rightBrush = new PolygonBrush(_rightLegGeom.LocalVertices, Color.BurlyWood, Color.Black, 1.0f, 0.5f);

            _topBrush.Load(device);
            _leftBrush.Load(device);
            _rightBrush.Load(device);
        }