Esempio n. 1
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Variables that will be set during input checking
            int toggleDirection;

            if (typingInput) // The user is typing input
            {
                bool inputAccepted = input.IsMenuSelect();
                bool inputCancelled = input.IsMenuCancel();
                bool inputBackspace = input.IsBackspace();
                String keysTyped = input.TypeableInput();

                if (inputAccepted || inputCancelled)
                {
                    typingInput = false;
                }
                if (inputAccepted || inputCancelled || inputBackspace || keysTyped != String.Empty)
                {
                    OnTyped(selectedEntry, inputAccepted, inputCancelled, inputBackspace, keysTyped);
                }
            }
            else // The user is performing normal menu input
            {
                // Move to the previous menu entry?
                if (input.IsMenuUp())
                {
                    if (!graphicalSelect)
                    {
                        menuScrollSoundEffect.Play();
                    }
                    do
                    {
                        selectedEntry--;
                        if (selectedEntry < 0)
                        {
                            selectedEntry = menuEntries.Count - 1;
                        }
                    } while (!menuEntries[selectedEntry].Enabled);
                }

                // Move to the next menu entry?
                if (input.IsMenuDown())
                {
                    if (!graphicalSelect)
                    {
                        menuScrollSoundEffect.Play();
                    }
                    do
                    {
                        selectedEntry++;
                        if (selectedEntry >= menuEntries.Count)
                        {
                            selectedEntry = 0;
                        }
                    } while (!menuEntries[selectedEntry].Enabled);
                }

                // Accept or cancel the menu?
                if (menuEntries[selectedEntry].Toggleable && input.IsMenuToggle(out toggleDirection))
                {
                    if (!graphicalSelect)
                    {
                        menuSelectSoundEffect.Play();
                    }
                    OnSelectEntry(selectedEntry, input.IsMenuSelect(), false, toggleDirection);
                }
                else if (input.IsMenuSelect())
                {
                    if (!graphicalSelect)
                    {
                        menuSelectSoundEffect.Play();
                    }
                    OnSelectEntry(selectedEntry, true, false, 0);
                }
                else if (input.IsMenuCancel())
                {
                    menuCancelSoundEffect.Play();
                    OnCancel();
                }
            }
            return;
        }
Esempio n. 2
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 = input.currentKeyboardState;
            GamePadState gamePadState = input.currentGamePadState;

            // 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;

            if (input.IsPauseGame() || gamePadDisconnected)
            {
                //pauseSoundEffect.Play();
                ScreenManager.AddScreen(new PauseMenuScreen());
            }
            else
            {
                //if the game is not paused, handle user input

                #region Handle Jump Input

                Vector2 movement = Vector2.Zero;
                float movementAcceleration = context.avatar.movementAcceleration;
                if (context.avatar.groundState == Entity.GroundState.AIR)
                    movementAcceleration /= 10.0f;

                context.avatar.acceleration = Vector2.Zero;

                context.avatar.acceleration.Y = context.avatar.onWall() ? GRAVITY / 2.0f : GRAVITY;

                //stillHoldingJump makes sure that, once our character hits the ground, he doesn't jump
                //again until we let go of the jump button and press it again
                stillHoldingJump |= context.avatar.groundState == Entity.GroundState.AIR;

                if (stillHoldingJump &&
                    (keyboardState.IsKeyUp(Keys.Space) && gamePadState.Buttons.A == ButtonState.Released))
                    //don't interpret the first key press as actually pressed, so that coming in from
                    //the menu doesn't make us jump
                    //NOTE: Feels VERY hacky, is there a better way?
                    if (firstRelease == false)
                    {
                        firstRelease = true;
                    }
                    else
                    {
                        stillHoldingJump = false;
                    }

                if (keyboardState.IsKeyDown(Keys.Space) ||
                    gamePadState.Buttons.A == ButtonState.Pressed)
                {
                    //if (firstRelease == true)
                    {
                        if (((context.avatar.groundState == Entity.GroundState.GROUND ||
                              context.avatar.onWall()) &&
                             !stillHoldingJump) ||
                            (context.avatar.groundState == Entity.GroundState.AIR &&
                             stillJumping &&
                             Math.Abs(context.avatar.velocity.Y) < context.avatar.maxVelocity))
                        {
                            if (context.avatar.onWall())
                                movementAcceleration *= -5;
                            context.avatar.acceleration.Y -= context.avatar.jumpAcceleration;
                            context.avatar.groundState = Entity.GroundState.AIR;
                            stillJumping = true;
                            stillHoldingJump = true;
                        }
                        else
                        {
                            //stillJumping makes sure we cannot jump infinitely
                            stillJumping = false;
                        }
                    }
                }

                #endregion

                #region Handle Left/Right Movement

                bool sliding = (keyboardState.IsKeyDown(Keys.LeftShift) ||
                                gamePadState.Buttons.B == ButtonState.Pressed);

                if (!sliding)
                {
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        context.avatar.acceleration.X = -movementAcceleration;
                        context.avatar.facing = TestMan.FacingState.LEFT;
                    }

                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        context.avatar.acceleration.X = movementAcceleration;
                        context.avatar.facing = TestMan.FacingState.RIGHT;
                    }

                    Vector2 thumbstick = gamePadState.ThumbSticks.Left;

                    if (thumbstick.X != 0)
                        context.avatar.acceleration.X = thumbstick.X * movementAcceleration;

                    if (keyboardState.IsKeyDown(Keys.LeftControl) ||
                        gamePadState.Buttons.RightShoulder == ButtonState.Pressed)
                        context.avatar.acceleration.X *= 2.0f;

                }

                context.avatar.velocity += context.avatar.acceleration;
                context.avatar.ignoreFriction = sliding;

                #endregion
            }
        }
Esempio n. 3
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)
 {
 }
Esempio n. 4
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input.IsMenuSelect())
            {
                okSoundEffect.Play();

                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                {
                    Accepted(this, new PlayerInputEventArgs(true));
                }

                ExitScreen();
            }
            else if (input.IsMenuCancel())
            {
                cancelSoundEffect.Play();

                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                {
                    Cancelled(this, new PlayerInputEventArgs(false, true));
                }

                ExitScreen();
            }
            return;
        }