Beispiel #1
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);
            }
        }
 public override void HandleInput(InputState input)
 {
     base.HandleInput(input);
     if (ControllingPlayer.HasValue)
     {
         // In single player games, handle input for the controlling player.
         HandlePlayerInput(input, ControllingPlayer.Value);
     }
 }
Beispiel #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)
 {
 }
        private bool HandlePlayerInput(InputState input, PlayerIndex playerIndex)
        {
            KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[(int)playerIndex];

            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                      input.GamePadWasConnected[(int)playerIndex];

            if (input.IsPauseGame(playerIndex) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), playerIndex);
                return false;
            }

            if (keyboardState.IsKeyDown(Keys.Left))
                GameController.Player.GoLeft(1.0);

            if (keyboardState.IsKeyDown(Keys.Right))
                GameController.Player.GoRight(1.0);

            if (keyboardState.IsKeyDown(Keys.Up))
                GameController.Player.GoUp(1.0);

            if (keyboardState.IsKeyDown(Keys.Down))
                GameController.Player.GoDown(1.0);

             if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.Triggers.Right > 0.1)
                 gameController.AddBullet();

            if (keyboardState.IsKeyDown(Keys.Q) && !oldState.IsKeyDown(Keys.Q)
                || gamePadState.Buttons.LeftShoulder == ButtonState.Pressed && oldPadState.Buttons.LeftShoulder != ButtonState.Pressed)
            {
                gameController.WeaponDown();
            }
            if (keyboardState.IsKeyDown(Keys.E) && !oldState.IsKeyDown(Keys.E)
                || gamePadState.Buttons.RightShoulder == ButtonState.Pressed && oldPadState.Buttons.RightShoulder != ButtonState.Pressed)
            {
                gameController.WeaponUp();
            }
            if (keyboardState.IsKeyDown(Keys.LeftControl) && !oldState.IsKeyDown(Keys.LeftControl)
                || gamePadState.Buttons.Y == ButtonState.Pressed && oldPadState.Buttons.Y != ButtonState.Pressed)
            {
                GameController.Player.ShieldOn = !GameController.Player.ShieldOn;
            }
            if (keyboardState.IsKeyDown(Keys.D1)) gameController.SetChoosenWeapon(1);
            if (keyboardState.IsKeyDown(Keys.D2)) gameController.SetChoosenWeapon(2);
            if (keyboardState.IsKeyDown(Keys.D3)) gameController.SetChoosenWeapon(3);
            if (keyboardState.IsKeyDown(Keys.D4)) gameController.SetChoosenWeapon(4);
            if (keyboardState.IsKeyDown(Keys.D5)) gameController.SetChoosenWeapon(5);
            if (keyboardState.IsKeyDown(Keys.D6)) gameController.SetChoosenWeapon(6);

            if (keyboardState.IsKeyDown(Keys.U) && !oldState.IsKeyDown(Keys.U))
            {
                paused = !paused;
            }

            if (keyboardState.IsKeyDown(Keys.LeftShift) ||
                    gamePadState.Buttons.X == ButtonState.Pressed)
            {
                GameController.Player.Boost(true);
            }
            else
            {
                GameController.Player.Boost(false);
            }

            Vector2 thumbstick = gamePadState.ThumbSticks.Left;
            if (thumbstick.X < -0.1)
            {
                GameController.Player.GoLeft(1.0);//thumbstick.X);
            }
             if (thumbstick.X > 0.1)
            {
                GameController.Player.GoRight(1.0);//thumbstick.X);
            }
            if (thumbstick.Y < -0.1)
            {
                GameController.Player.GoDown(1.0);//thumbstick.Y);
            }
             if (thumbstick.Y > 0.1)
            {
                GameController.Player.GoUp(1.0);//thumbstick.Y);
            }

            //     System.Diagnostics.Debug.WriteLine(thumbstick.X);
            oldState = keyboardState;
            oldPadState = gamePadState;
            return true;
        }
        /// <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();
            }
        }