O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required