/// <summary> /// Reads input data from keyboard and gamepad, and stores /// it into the specified player object. /// </summary> void ReadShipInputs(NetworkPlayer ship, PlayerIndex playerIndex) { // Read the gamepad. GamePadState gamePad = GamePad.GetState(playerIndex); Vector2 tankInput = gamePad.ThumbSticks.Left; Vector2 turretInput = gamePad.ThumbSticks.Right; // Read the keyboard. KeyboardState keyboard = Keyboard.GetState(playerIndex); if (keyboard.IsKeyDown(Keys.Left)) tankInput.X = -1; else if (keyboard.IsKeyDown(Keys.Right)) tankInput.X = 1; if (keyboard.IsKeyDown(Keys.Up)) tankInput.Y = 1; else if (keyboard.IsKeyDown(Keys.Down)) tankInput.Y = -1; if (keyboard.IsKeyDown(Keys.A)) turretInput.X = -1; else if (keyboard.IsKeyDown(Keys.D)) turretInput.X = 1; if (keyboard.IsKeyDown(Keys.W)) turretInput.Y = 1; else if (keyboard.IsKeyDown(Keys.S)) turretInput.Y = -1; // Normalize the input vectors. if (tankInput.Length() > 1) tankInput.Normalize(); if (turretInput.Length() > 1) turretInput.Normalize(); // Store these input values into the tank object. ship.TankInput = tankInput; ship.TurretInput = turretInput; }