Пример #1
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
            {
                // Movie Controls

                // Reset movie
                if ((gamePadState.Buttons.A == ButtonState.Pressed) || keyboardState.IsKeyDown(Keys.Enter))
                {
                    currentMovieFrame = 0;
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
 }
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
        /// <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;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
        /// <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;
        }