Time for action – accepting user input
To add
support for handling user input to the MarsRunnerPlayScreen
class, perform the following steps:
1. In the
Fields
region of theMarsRunnerPlayScreen
class, add two new fields to track the player's desired movement direction and the base movement speed as follows:int moveState = 0; int moveSpeed = 8;
2. Add the
HandleInput()
override method to theMarsRunnerPlayScreen
class as follows:#region Handle Input public override void HandleInput(InputState input) { moveState = 0; if ( (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left)) || (input.CurrentGamePadStates[0].ThumbSticks.Left.X < -0.3f) ) { moveState = 1; } if ( (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right)) || (input.CurrentGamePadStates[0].ThumbSticks.Left.X > 0.3f) ) { moveState = 2; } if ( (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up)) || (input.CurrentGamePadStates...