public Player(World world, float x, float y, Texture2D texture) { torso = BodyFactory.CreateRectangle(world, 60 * MainGame.PIXEL_TO_METER, 80 * MainGame.PIXEL_TO_METER, 1); torso.Position = new Vector2(x * MainGame.PIXEL_TO_METER, y * MainGame.PIXEL_TO_METER); torso.BodyType = BodyType.Dynamic; torso.UserData = this; legs = BodyFactory.CreateCircle(world, 31 * MainGame.PIXEL_TO_METER, 1); legs.Position = torso.Position + new Vector2(0, 40 * MainGame.PIXEL_TO_METER); legs.BodyType = BodyType.Dynamic; legs.Friction = 5.0f; legs.UserData = this; JointFactory.CreateFixedAngleJoint(world, torso); axis = JointFactory.CreateRevoluteJoint(world, torso, legs, Vector2.Zero); axis.CollideConnected = false; axis.MotorEnabled = true; axis.MotorSpeed = 0.0f; axis.MotorTorque = 3.0f; axis.MaxMotorTorque = 10.0f; onGround = false; facingLeft = false; jumpForce = new Vector2(0, -1f); rightAirForce = new Vector2(5f, 0); leftAirForce = -1 * rightAirForce; prevVelocity = Vector2.Zero; normal = Vector2.Zero; pressW = false; holdW = false; texIdle = new AnimatedTexture(texture, 24, 0, 0, 120, 140); texRun = new AnimatedTexture(texture, 19, 0, 140, 120, 140); texJump = new AnimatedTexture(texture, 9, 19 * 120, 140, 120, 140, 1, false, false); currentTexture = texIdle; }
///<Summary> /// This calls the base function and then attaches a motor between the upper body and wheel ///</Summary> public override void LoadContent(World world, String AssetName, Vector2 position, float Scale) { base.LoadContent(world, AssetName, position, Scale); //Create a joint between the upper body and wheel to hold the body upright fixedAngleJoint = JointFactory.CreateFixedAngleJoint(world, body); //Attach motor motor = JointFactory.CreateRevoluteJoint(world, body, wheel, Vector2.Zero); motor.MotorEnabled = true; motor.MaxMotorTorque = 1000f; motor.MotorSpeed = 0; //Make sure that the 2 bodies don't collide wheel.IgnoreCollisionWith(body); body.IgnoreCollisionWith(wheel); //Cause the wheel to firmly grip the surface wheel.Friction = float.MaxValue; this.world = world; }