/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Movie Controls // Reset movie if ((gamePadState.Buttons.A == ButtonState.Pressed) || keyboardState.IsKeyDown(Keys.Enter)) { currentMovieFrame = 0; } } }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Pacman move keys if ((gamePadState.DPad.Right == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Right))) { // Move pacman Right pacmanPos.X += pacmanSpeed; //Change Sprite currentFrame.Y = 0; } if ((gamePadState.DPad.Left == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Left))) { //Move Pacman left pacmanPos.X -= pacmanSpeed; //Change Sprite currentFrame.Y = 2; } if ((gamePadState.DPad.Down == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Down))) { //Move Pacman down pacmanPos.Y += pacmanSpeed; //Change Sprite currentFrame.Y = 1; } if ((gamePadState.DPad.Up == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Up))) { //Move Pacman Up pacmanPos.Y -= pacmanSpeed; //Change Sprite currentFrame.Y = 3; } } }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Pacman move keys if ((gamePadState.DPad.Right == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Right))) { // Move pacman Right pacmanPos.X += pacmanSpeed; //Change Sprite currentFrame.Y = 0; } if ((gamePadState.DPad.Left == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Left))) { //Move Pacman left pacmanPos.X -= pacmanSpeed; //Change Sprite currentFrame.Y = 2; } if ((gamePadState.DPad.Down == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Down))) { //Move Pacman down pacmanPos.Y += pacmanSpeed; //Change Sprite currentFrame.Y = 1; } if ((gamePadState.DPad.Up == ButtonState.Pressed) || (keyboardState.IsKeyDown(Keys.Up))) { //Move Pacman Up pacmanPos.Y -= pacmanSpeed; //Change Sprite currentFrame.Y = 3; } } }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Movie Controls // Reset movie if ((gamePadState.Buttons.A == ButtonState.Pressed) || keyboardState.IsKeyDown(Keys.Enter)) { currentMovieFrame = 0; } } }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } KeyboardState keyboardState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); if (input.IsPauseGame(ControllingPlayer)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { if (!piranha.IsInvul) { #region Keyboard toggle keys if (keyboardState.IsKeyDown(Keys.R) && prevKeyboard.IsKeyUp(Keys.R)) { ResetGame(); } if (keyboardState.IsKeyDown(Keys.M) && prevKeyboard.IsKeyUp(Keys.M)) { canUseMouse = !canUseMouse; } if (keyboardState.IsKeyDown(Keys.G) && prevKeyboard.IsKeyUp(Keys.G)) { godMode = !godMode; } #endregion #region Mouse control if (canUseMouse) { // Mouse control, can travel in all directions Vector2 mousePos = new Vector2(mouseState.X, mouseState.Y); Vector2 oldMousePos = new Vector2(prevMouse.X, prevMouse.Y); if (mousePos != oldMousePos) { piranha.WantedPosition = new Vector2(mouseState.X, mouseState.Y); } } #endregion #region Keyboard directional control keys if (keyboardState.IsKeyDown(Keys.Up)) { piranha.WantedPosition += new Vector2(0, -18); } else if (keyboardState.IsKeyDown(Keys.Down)) { piranha.WantedPosition += new Vector2(0, 18); } else if (keyboardState.IsKeyDown(Keys.Left)) { piranha.WantedPosition += new Vector2(-18, 0); } else if (keyboardState.IsKeyDown(Keys.Right)) { piranha.WantedPosition += new Vector2(18, 0); } #endregion // Clamp the wanted position to the screen bounds (with a little leeway) piranha.WantedPosition = new Vector2( MathHelper.Clamp(piranha.WantedPosition.X, -30, Functions.GameSize.X + 30), MathHelper.Clamp(piranha.WantedPosition.Y, -30, Functions.GameSize.Y + 30)); } } prevKeyboard = keyboardState; prevMouse = mouseState; }