Converting the Collision Game's Player Input Code
In the Update method of the Game1 class, you use the Keyboard object to see whether the user has pressed any keys to start
the game when it is in the GameState.Start game
state. Your code looks something like this:
if (Keyboard.GetState().GetPressedKeys( ).Length > 0)
{
currentGameState = GameState.InGame;
spriteManager.Enabled = true;
spriteManager.Visible = true;
}Change that code to the following to check for any key being pressed in the Windows project and to check for the Play/Pause button being pressed in the Zune project:
#if !ZUNE
if (Keyboard.GetState().GetPressedKeys( ).Length > 0)
#else
if(GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
#endif
{
currentGameState = GameState.InGame;
spriteManager.Enabled = true;
spriteManager.Visible = true;
}You do something similar later in the Update
method, in the GameState.GameOver game state.
That is, you check to see whether the player presses the Enter key and, if so, exit
the game:
if (Keyboard.GetState( ).IsKeyDown(Keys.Enter))
Exit( );Change that code to the following:
#if !ZUNE
if (Keyboard.GetState( ).IsKeyDown(Keys.Enter))
#else
if(GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
#endif
Exit( );The next change you'll need to make is in the UserControlledSprite class. In the direction accessor, you have code that uses the keyboard to move the
player object around the screen:
if (Keyboard.GetState( ).IsKeyDown(Keys.Left)) inputDirection.X −= ...