Time for action - handling input

  1. Add the following declarations to the declarations region of the Player class:
    private static Vector2 baseAngle = Vector2.Zero;
    private static Vector2 turretAngle = Vector2.Zero;
    private static float playerSpeed = 90f;
    
  2. Add the methods to handle keyboard and gamepad input to the Player class:
    #region Input Handling private static Vector2 handleKeyboardMovement(KeyboardState keyState) { Vector2 keyMovement = Vector2.Zero; if (keyState.IsKeyDown(Keys.W)) keyMovement.Y--; if (keyState.IsKeyDown(Keys.A)) keyMovement.X--; if (keyState.IsKeyDown(Keys.S)) keyMovement.Y++; if (keyState.IsKeyDown(Keys.D)) keyMovement.X++; return keyMovement; } private static Vector2 handleGamePadMovement(GamePadState gamepadState) { playerinput, ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.