private void GetInput(
KeyboardState keyboardState,
GamePadState gamePadState,
TouchCollection touchState,
AccelerometerState accelState,
DisplayOrientation orientation,
InputManager inputManager)
{
// Get analog horizontal movement.
movement.X = gamePadState.ThumbSticks.Left.X * MoveStickScale;
// Get analog vertical movement.
movement.Y = gamePadState.ThumbSticks.Left.Y * MoveStickScale;
// Ignore small movements to prevent running in place.
if (Math.Abs(movement.X) < 0.5f)
{
movement.X = 0.0f;
}
if (Math.Abs(movement.Y) < 0.5f)
{
movement.Y = 0.0f;
}
/*
// Move the player with accelerometer
if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
{
// set our movement speed
movement = MathHelper.Clamp(-accelState.Acceleration.Y * AccelerometerScale, -1f, 1f);
// if we're in the LandscapeLeft orientation, we must reverse our movement
if (orientation == DisplayOrientation.LandscapeRight)
movement = -movement;
}
*/
// If any digital horizontal movement input is found, override the analog movement.
if (gamePadState.IsButtonDown(Buttons.DPadLeft) ||
keyboardState.IsKeyDown(Keys.Left) ||
keyboardState.IsKeyDown(Keys.A))
{
movement.X = -1.0f;
}
else if (gamePadState.IsButtonDown(Buttons.DPadRight) ||
keyboardState.IsKeyDown(Keys.Right) ||
keyboardState.IsKeyDown(Keys.D))
{
movement.X = 1.0f;
}
// Handle ladder up input
if (gamePadState.IsButtonDown(Buttons.DPadUp) ||
keyboardState.IsKeyDown(Keys.Up) ||
keyboardState.IsKeyDown(Keys.W))
{
isClimbing = false;
//makes sure the players position is aligned to the center of the ladder
if (IsAlignedToLadder())
{
//need to check the tile behind the player, not what he is standing on
if (level.GetTileCollisionBehindPlayer(position) == TileCollision.Ladder)
{
isClimbing = true;
isJumping = false;
isOnGround = false;
movement.Y = -1.0f;
}
}
}
// Handle ladder down input
else if (gamePadState.IsButtonDown(Buttons.DPadDown) ||
keyboardState.IsKeyDown(Keys.Down) ||
keyboardState.IsKeyDown(Keys.S))
{
isClimbing = false;
//makes sure the players position is aligned to the center of the ladder
if (IsAlignedToLadder())
{
//need to check the tile that the player is standing on
if (level.GetTileCollisionBelowPlayer(this.Position) == TileCollision.Ladder)
{
isClimbing = true;
isJumping = false;
isOnGround = false;
movement.Y = 2.0f;
}
}
}
// Check if the player wants to jump.
// Change this so that we only want to jump if it is a new press - i.e. KeyPressDown()
//
//isJumping = gamePadState.IsButtonDown(JumpButton) || keyboardState.IsKeyDown(Keys.Space) || keyboardState.IsKeyDown(Keys.Up) ||
// keyboardState.IsKeyDown(Keys.W) || touchState.AnyTouch();
isJumping = inputManager.IsNewPress(JumpButton) || inputManager.IsNewPress(Keys.Space) || inputManager.IsNewPress(Keys.Up) ||
inputManager.IsNewPress(Keys.W);
}