public TheoJansenWalker(World world, PhysicsGameScreen screen, Vector2 position) { _position = position; _motorSpeed = 2.0f; _motorOn = true; _screen = screen; _walkerJoints = new List<DistanceJoint>(); _leftShoulders = new Body[3]; _rightShoulders = new Body[3]; _leftLegs = new Body[3]; _rightLegs = new Body[3]; Vector2 pivot = new Vector2(0f, -0.8f); // Chassis { PolygonShape shape = new PolygonShape(1f); shape.SetAsBox(2.5f, 1.0f); _body = new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Blank, Color.Beige, 1f)); _chassis = BodyFactory.CreateBody(world); _chassis.BodyType = BodyType.Dynamic; _chassis.Position = pivot + _position; Fixture fixture = _chassis.CreateFixture(shape); fixture.CollisionGroup = -1; } { CircleShape shape = new CircleShape(1.6f, 1f); _engine = new Sprite(_screen.ScreenManager.Assets.TextureFromShape(shape, MaterialType.Waves, Color.Beige * 0.8f, 1f)); _wheel = BodyFactory.CreateBody(world); _wheel.BodyType = BodyType.Dynamic; _wheel.Position = pivot + _position; Fixture fixture = _wheel.CreateFixture(shape); fixture.CollisionGroup = -1; } { _motorJoint = new RevoluteJoint(_wheel, _chassis, _wheel.GetLocalPoint(_chassis.Position), Vector2.Zero); _motorJoint.CollideConnected = false; _motorJoint.MotorSpeed = _motorSpeed; _motorJoint.MaxMotorTorque = 400f; _motorJoint.MotorEnabled = _motorOn; world.AddJoint(_motorJoint); } Vector2 wheelAnchor = pivot + new Vector2(0f, 0.8f); CreateLegTextures(); CreateLeg(world, -1f, wheelAnchor, 0); CreateLeg(world, 1f, wheelAnchor, 0); _leftLeg.Origin = AssetCreator.CalculateOrigin(_leftLegs[0]); _leftShoulder.Origin = AssetCreator.CalculateOrigin(_leftShoulders[0]); _rightLeg.Origin = AssetCreator.CalculateOrigin(_rightLegs[0]); _rightShoulder.Origin = AssetCreator.CalculateOrigin(_rightShoulders[0]); _wheel.SetTransform(_wheel.Position, 120f * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 1); CreateLeg(world, 1f, wheelAnchor, 1); _wheel.SetTransform(_wheel.Position, -120f * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 2); CreateLeg(world, 1f, wheelAnchor, 2); }
private TheoJansenTest() { _offset = new Vector2(0.0f, 8.0f); _motorSpeed = 2.0f; _motorOn = true; Vector2 pivot = new Vector2(0.0f, 0.8f); // Ground { Body ground = BodyFactory.CreateEdge(World, new Vector2(-50.0f, 0.0f), new Vector2(50.0f, 0.0f)); FixtureFactory.AttachEdge(new Vector2(-50.0f, 0.0f), new Vector2(-50.0f, 10.0f), ground); FixtureFactory.AttachEdge(new Vector2(50.0f, 0.0f), new Vector2(50.0f, 10.0f), ground); } // Balls for (int i = 0; i < 40; ++i) { CircleShape shape = new CircleShape(0.25f, 1); Body body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(-40.0f + 2.0f * i, 0.5f); body.CreateFixture(shape); } // Chassis { PolygonShape shape = new PolygonShape(1); shape.Vertices = PolygonTools.CreateRectangle(2.5f, 1.0f); _chassis = BodyFactory.CreateBody(World); _chassis.BodyType = BodyType.Dynamic; _chassis.Position = pivot + _offset; Fixture fixture = _chassis.CreateFixture(shape); fixture.CollisionGroup = -1; } { CircleShape shape = new CircleShape(1.6f, 1); _wheel = BodyFactory.CreateBody(World); _wheel.BodyType = BodyType.Dynamic; _wheel.Position = pivot + _offset; Fixture fixture = _wheel.CreateFixture(shape); fixture.CollisionGroup = -1; } { _motorJoint = new RevoluteJoint(_wheel, _chassis, _chassis.Position, true); _motorJoint.CollideConnected = false; _motorJoint.MotorSpeed = _motorSpeed; _motorJoint.MaxMotorTorque = 400.0f; _motorJoint.MotorEnabled = _motorOn; World.AddJoint(_motorJoint); } Vector2 wheelAnchor = pivot + new Vector2(0.0f, -0.8f); CreateLeg(-1.0f, wheelAnchor); CreateLeg(1.0f, wheelAnchor); _wheel.SetTransform(_wheel.Position, 120.0f * Settings.Pi / 180.0f); CreateLeg(-1.0f, wheelAnchor); CreateLeg(1.0f, wheelAnchor); _wheel.SetTransform(_wheel.Position, -120.0f * Settings.Pi / 180.0f); CreateLeg(-1.0f, wheelAnchor); CreateLeg(1.0f, wheelAnchor); }
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)); _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 * Settings.Pi / 180f); CreateLeg(world, -1f, wheelAnchor, 1); CreateLeg(world, 1f, wheelAnchor, 1); _wheel.SetTransform(_wheel.Position, -120f * Settings.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]); }
public Ragdoll(World world, Vector2 position) { // Physics // Head _head = BodyFactory.CreateCircle(world, 0.75f, 10f); _head.BodyType = BodyType.Dynamic; _head.AngularDamping = LimbAngularDamping; _head.Mass = 2f; _head.Position = position; // Torso _upperBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _upperBody.BodyType = BodyType.Dynamic; _upperBody.Mass = 1f; _upperBody.SetTransform(position + new Vector2(0f, 1.75f), MathHelper.Pi / 2f); _middleBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _middleBody.BodyType = BodyType.Dynamic; _middleBody.Mass = 1f; _middleBody.SetTransform(position + new Vector2(0f, 3f), MathHelper.Pi / 2f); _lowerBody = BodyFactory.CreateCapsule(world, 0.5f, 0.75f, LegDensity); _lowerBody.BodyType = BodyType.Dynamic; _lowerBody.Mass = 1f; _lowerBody.SetTransform(position + new Vector2(0f, 4.25f), MathHelper.Pi / 2f); // Left Arm _lowerLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _lowerLeftArm.BodyType = BodyType.Dynamic; _lowerLeftArm.AngularDamping = LimbAngularDamping; _lowerLeftArm.Mass = 2f; _lowerLeftArm.Rotation = 1.4f; _lowerLeftArm.Position = position + new Vector2(-4f, 2.2f); _upperLeftArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _upperLeftArm.BodyType = BodyType.Dynamic; _upperLeftArm.AngularDamping = LimbAngularDamping; _upperLeftArm.Mass = 2f; _upperLeftArm.Rotation = 1.4f; _upperLeftArm.Position = position + new Vector2(-2f, 1.8f); // Right Arm _lowerRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _lowerRightArm.BodyType = BodyType.Dynamic; _lowerRightArm.AngularDamping = LimbAngularDamping; _lowerRightArm.Mass = 2f; _lowerRightArm.Rotation = -1.4f; _lowerRightArm.Position = position + new Vector2(4f, 2.2f); _upperRightArm = BodyFactory.CreateCapsule(world, 1f, 0.45f, ArmDensity); _upperRightArm.BodyType = BodyType.Dynamic; _upperRightArm.AngularDamping = LimbAngularDamping; _upperRightArm.Mass = 2f; _upperRightArm.Rotation = -1.4f; _upperRightArm.Position = position + new Vector2(2f, 1.8f); // Left Leg _lowerLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _lowerLeftLeg.BodyType = BodyType.Dynamic; _lowerLeftLeg.AngularDamping = LimbAngularDamping; _lowerLeftLeg.Mass = 2f; _lowerLeftLeg.Position = position + new Vector2(-0.6f, 8f); _upperLeftLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _upperLeftLeg.BodyType = BodyType.Dynamic; _upperLeftLeg.AngularDamping = LimbAngularDamping; _upperLeftLeg.Mass = 2f; _upperLeftLeg.Position = position + new Vector2(-0.6f, 6f); // Right Leg _lowerRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _lowerRightLeg.BodyType = BodyType.Dynamic; _lowerRightLeg.AngularDamping = LimbAngularDamping; _lowerRightLeg.Mass = 2f; _lowerRightLeg.Position = position + new Vector2(0.6f, 8f); _upperRightLeg = BodyFactory.CreateCapsule(world, 1f, 0.5f, LegDensity); _upperRightLeg.BodyType = BodyType.Dynamic; _upperRightLeg.AngularDamping = LimbAngularDamping; _upperRightLeg.Mass = 2f; _upperRightLeg.Position = position + new Vector2(0.6f, 6f); // head -> upper body DistanceJoint jointHeadBody = new DistanceJoint(_head, _upperBody, new Vector2(0f, 1f), new Vector2(-0.75f, 0f)); jointHeadBody.CollideConnected = true; jointHeadBody.DampingRatio = DampingRatio; jointHeadBody.Frequency = Frequency; jointHeadBody.Length = 0.025f; world.AddJoint(jointHeadBody); // lowerLeftArm -> upperLeftArm DistanceJoint jointLeftArm = new DistanceJoint(_lowerLeftArm, _upperLeftArm, new Vector2(0f, -1f), new Vector2(0f, 1f)); jointLeftArm.CollideConnected = true; jointLeftArm.DampingRatio = DampingRatio; jointLeftArm.Frequency = Frequency; jointLeftArm.Length = 0.02f; world.AddJoint(jointLeftArm); // upperLeftArm -> upper body DistanceJoint jointLeftArmBody = new DistanceJoint(_upperLeftArm, _upperBody, new Vector2(0f, -1f), new Vector2(-0.15f, 1f)); jointLeftArmBody.DampingRatio = DampingRatio; jointLeftArmBody.Frequency = Frequency; jointLeftArmBody.Length = 0.02f; world.AddJoint(jointLeftArmBody); // lowerRightArm -> upperRightArm DistanceJoint jointRightArm = new DistanceJoint(_lowerRightArm, _upperRightArm, new Vector2(0f, -1f), new Vector2(0f, 1f)); jointRightArm.CollideConnected = true; jointRightArm.DampingRatio = DampingRatio; jointRightArm.Frequency = Frequency; jointRightArm.Length = 0.02f; world.AddJoint(jointRightArm); // upperRightArm -> upper body DistanceJoint jointRightArmBody = new DistanceJoint(_upperRightArm, _upperBody, new Vector2(0f, -1f), new Vector2(-0.15f, -1f)); jointRightArmBody.DampingRatio = DampingRatio; jointRightArmBody.Frequency = 25; jointRightArmBody.Length = 0.02f; world.AddJoint(jointRightArmBody); // lowerLeftLeg -> upperLeftLeg DistanceJoint jointLeftLeg = new DistanceJoint(_lowerLeftLeg, _upperLeftLeg, new Vector2(0f, -1.1f), new Vector2(0f, 1f)); jointLeftLeg.CollideConnected = true; jointLeftLeg.DampingRatio = DampingRatio; jointLeftLeg.Frequency = Frequency; jointLeftLeg.Length = 0.05f; world.AddJoint(jointLeftLeg); // upperLeftLeg -> lower body DistanceJoint jointLeftLegBody = new DistanceJoint(_upperLeftLeg, _lowerBody, new Vector2(0f, -1.1f), new Vector2(0.7f, 0.8f)); jointLeftLegBody.CollideConnected = true; jointLeftLegBody.DampingRatio = DampingRatio; jointLeftLegBody.Frequency = Frequency; jointLeftLegBody.Length = 0.02f; world.AddJoint(jointLeftLegBody); // lowerRightleg -> upperRightleg DistanceJoint jointRightLeg = new DistanceJoint(_lowerRightLeg, _upperRightLeg, new Vector2(0f, -1.1f), new Vector2(0f, 1f)); jointRightLeg.CollideConnected = true; jointRightLeg.DampingRatio = DampingRatio; jointRightLeg.Frequency = Frequency; jointRightLeg.Length = 0.05f; world.AddJoint(jointRightLeg); // upperRightleg -> lower body DistanceJoint jointRightLegBody = new DistanceJoint(_upperRightLeg, _lowerBody, new Vector2(0f, -1.1f), new Vector2(0.7f, -0.8f)); jointRightLegBody.CollideConnected = true; jointRightLegBody.DampingRatio = DampingRatio; jointRightLegBody.Frequency = Frequency; jointRightLegBody.Length = 0.02f; world.AddJoint(jointRightLegBody); // upper body -> middle body RevoluteJoint jointUpperTorso = new RevoluteJoint(_upperBody, _middleBody, _upperBody.Position + new Vector2(0f, 0.625f), true); jointUpperTorso.LimitEnabled = true; jointUpperTorso.SetLimits(-MathHelper.Pi / 16f, MathHelper.Pi / 16f); world.AddJoint(jointUpperTorso); // middle body -> lower body RevoluteJoint jointLowerTorso = new RevoluteJoint(_middleBody, _lowerBody, _middleBody.Position + new Vector2(0f, 0.625f), true); jointLowerTorso.LimitEnabled = true; jointLowerTorso.SetLimits(-MathHelper.Pi / 8f, MathHelper.Pi / 8f); world.AddJoint(jointLowerTorso); // GFX _face = new Sprite(ContentWrapper.CircleTexture(0.75f, "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Grey, 1f)); _torso = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateRoundedRectangle(1.5f, 2f, 0.75f, 0.75f, 2), "Stripe", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 2.0f)); _upperLimb = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateCapsule(1.9f, 0.45f, 16), "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 1f)); _lowerLimb = new Sprite(ContentWrapper.PolygonTexture(PolygonTools.CreateCapsule(2f, 0.5f, 16), "Square", ContentWrapper.Gold, ContentWrapper.Orange, ContentWrapper.Black, 1f)); }
protected void SetPhysicalState(object nState) { List<Body> mOldBodies = mBodies; if (mSpriteEffects == SpriteEffects.FlipHorizontally) { mBodies = mBodiesLeft; } else { mBodies = mBodiesRight; } //If mBody == null, the player is being loaded for the first time if (mBody == null) { mBody = mBodies[mStates.IndexOf(nState)]; mBody.Enabled = true; //mBody.Awake = true; //mBody.IgnoreGravity = false; //mBody.CollidesWith = Category.All; //mBody.Positi = mStartPos; mBody.IgnoreGravity = false; mBody.CollisionCategories = Category.Cat1; mBody.CollidesWith = Category.All & ~Category.Cat2; mBody.CollisionGroup = -1; } else { //Set new body mBody = mBodies[mStates.IndexOf(nState)]; //Disable old body mOldBodies[mStates.IndexOf(mState)].CollisionCategories = Category.Cat2; mOldBodies[mStates.IndexOf(mState)].CollidesWith = Category.None; mOldBodies[mStates.IndexOf(mState)].CollisionGroup = -2; //Enable new body mBody.IgnoreGravity = false; mBody.CollisionCategories = Category.Cat1; mBody.CollidesWith = Category.All & ~Category.Cat2; mBody.CollisionGroup = -1; //Copy properties to new body mBody.SetTransform(mOldBodies[mStates.IndexOf(mState)].Position, mOldBodies[mStates.IndexOf(mState)].Rotation); mBody.LinearVelocity = mOldBodies[mStates.IndexOf(mState)].LinearVelocity; mBody.AngularVelocity = mOldBodies[mStates.IndexOf(mState)].AngularVelocity; } }
protected void ConstructGenericMan() { #region Torso //Torso Vector2 size = new Vector2(20f / PPM, 36f / PPM); torso = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); torso.UserData = new PhysicalData(size, this, medColor); torso.Position = position / PPM; torso.FixedRotation = true; torso.BodyType = BodyType.Dynamic; torso.Restitution = 0.2f; torso.Friction = 0.2f; torso.SleepingAllowed = false; torso.CollisionCategories = Category.Cat2; torso.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //FixtureFactory.AttachRectangle(20f / PPM, 20f / PPM, 5f, new Vector2(0f, -20f), torso); #endregion #region Head //Head size = new Vector2(26f / PPM, 26f / PPM); head = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); head.UserData = new PhysicalData(size, this, medColor); head.Position = (position + new Vector2(0f, -38f)) / PPM; head.BodyType = BodyType.Dynamic; head.Restitution = 0.2f; head.Friction = 0.2f; head.AngularDamping = 1.2f; head.SetTransform(head.Position, 0.1f); head.SleepingAllowed = false; head.CollisionCategories = Category.Cat2; head.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join head to body neck = JointFactory.CreateRevoluteJoint(world, torso, head, new Vector2(0f, 0f)); #endregion #region Arms #region Right Arm //Right Arm size = new Vector2(15f / PPM, 25f / PPM); rArm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); rArm.UserData = new PhysicalData(size, this, color); rArm.Position = (position + new Vector2(0f, -6f)) / PPM; rArm.BodyType = BodyType.Dynamic; rArm.Restitution = 0.2f; rArm.Friction = 0.2f; rArm.SleepingAllowed = false; rArm.CollisionCategories = Category.Cat2; rArm.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join right arm to body //JointFactory.CreateRevoluteJoint(world, torso, rArm, new Vector2(0f, -4f / PPM)); rShoulder = new RevoluteJoint(torso, rArm, new Vector2(0f / PPM, -15f / PPM), new Vector2(0f / PPM, -10f / PPM)); //rShoulder.LowerLimit = -(float)Math.PI / 1.5f; //rShoulder.UpperLimit = (float)Math.PI / 3f; //rShoulder.LimitEnabled = true; rShoulder.MotorEnabled = true; rShoulder.MaxMotorTorque = JOINT_MAX_TORQUE; rShoulder.MotorSpeed = 0; world.AddJoint(rShoulder); //Right Forearm size = new Vector2(18f / PPM, 30f / PPM); rForearm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); rForearm.UserData = new PhysicalData(size, this, color); rForearm.Position = (position + new Vector2(0f, 4f)) / PPM; rForearm.BodyType = BodyType.Dynamic; rForearm.Restitution = 0.2f; rForearm.Friction = 0.2f; rForearm.AngularDamping = 0.8f; rForearm.SleepingAllowed = false; rForearm.CollisionCategories = Category.Cat2; rForearm.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join right forearm to right arm //JointFactory.CreateRevoluteJoint(world, rArm, rForearm, new Vector2(0f, 4f / PPM)); rElbow = new RevoluteJoint(rArm, rForearm, new Vector2(0f / PPM, 15f / PPM), new Vector2(0f / PPM, -10f / PPM)); //rElbow.LowerLimit = -(float)Math.PI / 1.5f; //rElbow.UpperLimit = (float)Math.PI / 3f; //rElbow.LimitEnabled = true; rElbow.MotorEnabled = true; rElbow.MaxMotorTorque = JOINT_MAX_TORQUE; rElbow.MotorSpeed = 0; world.AddJoint(rElbow); #endregion #region Left Arm //Left Arm size = new Vector2(15f / PPM, 25f / PPM); lArm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); lArm.UserData = new PhysicalData(size, this, darkColor); lArm.Position = (position + new Vector2(0f, -6f)) / PPM; lArm.BodyType = BodyType.Dynamic; lArm.Restitution = 0.2f; lArm.Friction = 0.2f; lArm.SleepingAllowed = false; lArm.CollisionCategories = Category.Cat2; lArm.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join Left arm to body //JointFactory.CreateRevoluteJoint(world, torso, lArm, new Vector2(0f, -4f / PPM)); lShoulder = new RevoluteJoint(torso, lArm, new Vector2(0f / PPM, -15f / PPM), new Vector2(0f / PPM, -10f / PPM)); //lShoulder.LowerLimit = -(float)Math.PI / 1.5f; //lShoulder.UpperLimit = (float)Math.PI / 3f; //lShoulder.LimitEnabled = true; lShoulder.MotorEnabled = true; lShoulder.MaxMotorTorque = JOINT_MAX_TORQUE; lShoulder.MotorSpeed = 0; world.AddJoint(lShoulder); //Left Forearm size = new Vector2(18f / PPM, 30f / PPM); lForearm = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); lForearm.UserData = new PhysicalData(size, this, darkColor); lForearm.Position = (position + new Vector2(0f, 4f)) / PPM; lForearm.BodyType = BodyType.Dynamic; lForearm.Restitution = 0.2f; lForearm.Friction = 0.2f; lForearm.AngularDamping = 0.8f; lForearm.SleepingAllowed = false; lForearm.CollisionCategories = Category.Cat2; lForearm.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join Left forearm to Left arm //JointFactory.CreateRevoluteJoint(world, lArm, lForearm, new Vector2(0f, 4f / PPM)); lElbow = new RevoluteJoint(lArm, lForearm, new Vector2(0f / PPM, 15f / PPM), new Vector2(0f / PPM, -10f / PPM)); //lElbow.LowerLimit = -(float)Math.PI / 1.5f; //lElbow.UpperLimit = (float)Math.PI / 3f; //lElbow.LimitEnabled = true; lElbow.MotorEnabled = true; lElbow.MaxMotorTorque = JOINT_MAX_TORQUE; lElbow.MotorSpeed = 0; world.AddJoint(lElbow); #endregion #endregion #region Legs #region Right Leg //Right Thigh size = new Vector2(15f / PPM, 30f / PPM); rThigh = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); rThigh.UserData = new PhysicalData(size, this, medColor); rThigh.Position = (position + new Vector2(30f, 45f)) / PPM; rThigh.BodyType = BodyType.Dynamic; rThigh.Restitution = 0.2f; rThigh.Friction = 0.2f; rThigh.SleepingAllowed = false; rThigh.CollisionCategories = Category.Cat2; rThigh.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join right Thigh to body //JointFactory.CreateRevoluteJoint(world, torso, rThigh, new Vector2(0f, -10f / PPM)); rHip = new RevoluteJoint(torso, rThigh, new Vector2(0f / PPM, 20f / PPM), new Vector2(0f / PPM, -10f / PPM)); //rHip.LowerLimit = -(float)Math.PI / 1.5f; //rHip.UpperLimit = (float)Math.PI / 3f; //rHip.LimitEnabled = true; rHip.MotorEnabled = true; rHip.MaxMotorTorque = JOINT_MAX_TORQUE; rHip.MotorSpeed = 0; world.AddJoint(rHip); //Right Leg size = new Vector2(25f / PPM, 35f / PPM); rLeg = BodyFactory.CreateRectangle(world, 25f / PPM, 35f / PPM, 10f); rLeg.UserData = new PhysicalData(size, this, medColor); rLeg.Position = (position + new Vector2(0f, 16f)) / PPM; rLeg.BodyType = BodyType.Dynamic; rLeg.Restitution = 0.2f; rLeg.Friction = 0.8f; rLeg.AngularDamping = 0.8f; rLeg.SleepingAllowed = false; rLeg.CollisionCategories = Category.Cat2; rLeg.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; rLeg.OnCollision += CharacterCollision; //Join right Leg to right thigh //JointFactory.CreateRevoluteJoint(world, rThigh, rLeg, new Vector2(0f, 20f / PPM)); rKnee = new RevoluteJoint(rThigh, rLeg, new Vector2(0f / PPM, 15f / PPM)); //rKnee.LowerLimit = -(float)Math.PI; //rKnee.UpperLimit = -(float)Math.PI / 3f; //rKnee.LimitEnabled = true; rKnee.MotorEnabled = true; rKnee.MaxMotorTorque = JOINT_MAX_TORQUE; rKnee.MotorSpeed = 0; world.AddJoint(rKnee); #endregion #region Left Leg //Left Thigh size = new Vector2(15f / PPM, 30f / PPM); lThigh = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); lThigh.UserData = new PhysicalData(size, this, darkColor); lThigh.Position = (position + new Vector2(30f, 45f)) / PPM; lThigh.BodyType = BodyType.Dynamic; lThigh.Restitution = 0.2f; lThigh.Friction = 0.2f; lThigh.SleepingAllowed = false; lThigh.CollisionCategories = Category.Cat2; lThigh.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; //Join Left Thigh to body //JointFactory.CreateRevoluteJoint(world, torso, rThigh, new Vector2(0f, -10f / PPM)); lHip = new RevoluteJoint(torso, lThigh, new Vector2(0f / PPM, 20f / PPM), new Vector2(0f / PPM, -10f / PPM)); //lHip.LowerLimit = -(float)Math.PI / 1.5f; //lHip.UpperLimit = (float)Math.PI / 3f; //lHip.LimitEnabled = true; lHip.MotorEnabled = true; lHip.MaxMotorTorque = JOINT_MAX_TORQUE; lHip.MotorSpeed = 0; world.AddJoint(lHip); //Left Leg size = new Vector2(25f / PPM, 35f / PPM); lLeg = BodyFactory.CreateRectangle(world, size.X, size.Y, 10f); lLeg.UserData = new PhysicalData(size, this, darkColor); lLeg.Position = (position + new Vector2(0f, 16f)) / PPM; lLeg.BodyType = BodyType.Dynamic; lLeg.Restitution = 0.2f; lLeg.Friction = 0.8f; lLeg.AngularDamping = 0.8f; lLeg.SleepingAllowed = false; lLeg.CollisionCategories = Category.Cat2; lLeg.CollidesWith = Category.Cat1 | Category.Cat3 | Category.Cat5; lLeg.OnCollision += CharacterCollision; //Join right Leg to right thigh //JointFactory.CreateRevoluteJoint(world, rThigh, rLeg, new Vector2(0f, 20f / PPM)); lKnee = new RevoluteJoint(lThigh, lLeg, new Vector2(0f / PPM, 15f / PPM)); //lKnee.LowerLimit = -(float)Math.PI; //lKnee.UpperLimit = -(float)Math.PI / 3f; //lKnee.LimitEnabled = true; lKnee.MotorEnabled = true; lKnee.MaxMotorTorque = JOINT_MAX_TORQUE; lKnee.MotorSpeed = 0; world.AddJoint(lKnee); #endregion #endregion #region Add to Display List //Add all body parts to parts list bodyParts.Add(lForearm); bodyParts.Add(lArm); bodyParts.Add(lLeg); bodyParts.Add(lThigh); bodyParts.Add(torso); bodyParts.Add(head); bodyParts.Add(rThigh); bodyParts.Add(rLeg); bodyParts.Add(rArm); bodyParts.Add(rForearm); //Add all joints to joints list joints.Add(neck); joints.Add(rShoulder); joints.Add(lShoulder); joints.Add(rElbow); joints.Add(lElbow); joints.Add(rHip); joints.Add(lHip); joints.Add(rKnee); joints.Add(lKnee); #endregion }
public static void SetTransform(Body body, Transform2 transform) { body.SetTransform((Xna.Vector2)transform.Position, transform.Rotation); }