コード例 #1
0
        public override void HandleInput(InputState input)
        {
            if (input.IsPauseGame(ControllingPlayer))
            {
                ScreenManager.AddScreen(new PauseMenuScreen(GameType.Training));
            }
            else
            {
                player.UpdateInput(input, PlayerIndex.One);
            }

			player.UpdateClamp(ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Top,
				ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Bottom,
				ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Left,
				ScreenManager.GraphicsDevice.Viewport.TitleSafeArea.Right);
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: JoshuaKennedy/DarkHavoc
        public void UpdateInput(InputState input, PlayerIndex? controllingPlayer)
        {
            // Look up inputs for the active player profile.
            int playerIndex = (int)controllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
			GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

			if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.IsButtonDown(Buttons.DPadLeft))
            {
                Position.X -= Speed;
            }

			if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.IsButtonDown(Buttons.DPadRight) )
            {
                Position.X += Speed;
            }

			if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.IsButtonDown(Buttons.DPadUp))
            {
                Position.Y -= Speed;
            }

			if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.IsButtonDown(Buttons.DPadDown))
            {
                Position.Y += Speed;
            }

			if (keyboardState.Equals(new KeyboardState()))
			{
				Vector2 thumbstick = gamePadState.ThumbSticks.Left;

				this.Position.X += thumbstick.X * this.Speed;
				this.Position.Y -= thumbstick.Y * this.Speed;
			}
        }
コード例 #3
0
        public override void HandleInput(InputState input)
        {
            if (!passThrough)
            {
                // We need input to not be null.
                if (input == null)
                    throw new ArgumentNullException("input");

                // Get the keyboard and gamepad states.
                KeyboardState keyboardState = Keyboard.GetState();
                GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);

				// If the number keys on the keyboard is greater than 0 (in case they're pressing 2 keys at once)...
                // or the mouse is clicked
                if (keyboardState.GetPressedKeys().Length > 0 || input.IsNewLeftMouseClick())
                {
                    // Proceed to the main menu.
                    GotoMainMenu();
                }

                // If the start, a, b, x, or y buttons are being pressed...
                if (gamePadState.IsButtonDown(Buttons.Start) || gamePadState.IsButtonDown(Buttons.A) || gamePadState.IsButtonDown(Buttons.B) || gamePadState.IsButtonDown(Buttons.X) || gamePadState.IsButtonDown(Buttons.Y))
                {
                    // Proceed to the main menu.
                    GotoMainMenu();
                }
            }
        }
コード例 #4
0
 private void CheckButtonClick(InputState input, MenuButton button)
 {
     // If we clicked the mouse
     if (input.IsNewLeftMouseClick())
     {
         // We check the mouse to see if we're in the confines of the button and the button is enabled and we can use the mouse.
         if (input.LastMouseState.X > button.RectangleCollider.Left &&
             input.LastMouseState.X < button.RectangleCollider.Right &&
             input.LastMouseState.Y < button.RectangleCollider.Bottom &&
             input.LastMouseState.Y > button.RectangleCollider.Top &&
             button.IsEnabled)
         {
             // Fire the button's selected event.
             button.OnSelectEntry(PlayerIndex.One);
         }
     }
 }
コード例 #5
0
        public override void HandleInput(InputState input)
        {
            // Left mouse click
            
            // Play Game Button
            CheckButtonClick(input, playGameButton);

            // Options/Help button
            CheckButtonClick(input, optionsHelpButton);

            // Exit button
            CheckButtonClick(input, exitButton);

            // Hovering

            // Play Game Button
            CheckButtonHover(input, playGameButton);
            
            // Options/Help button
            CheckButtonHover(input, optionsHelpButton);

            // Exit button.
            CheckButtonHover(input, exitButton);
        }
コード例 #6
0
 private void CheckButtonHover(InputState input, MenuButton button)
 {
     // We check the mouse to see if we're in the confines of the button and the button is enabled and we can use the mouse.
     if (input.LastMouseState.X > button.RectangleCollider.Left &&
         input.LastMouseState.X < button.RectangleCollider.Right &&
         input.LastMouseState.Y < button.RectangleCollider.Bottom &&
         input.LastMouseState.Y > button.RectangleCollider.Top &&
         button.IsEnabled)
     {
         // Set the hovering to true.
         button.IsHovering = true;
     }
     else
     {
         // Set the hovering to false.
         button.IsHovering = false;
     }
 }
コード例 #7
0
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            if (input.IsMenuCancel(null, out playerIndex))
            {
                creditsFinished = true;
                OnCreditsEnd(playerIndex);
            }
        }
コード例 #8
0
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            mouseState = Mouse.GetState();

            mousePosition = new Vector2(mouseState.X, mouseState.Y);

            if (input.IsNewKeyPress(Keys.Left, ControllingPlayer, out playerIndex) && !useMouse)
            {
                MoveMenuLeft();
                useMouse = false;
            }
            else if (input.IsNewKeyPress(Keys.Right, ControllingPlayer, out playerIndex) && !useMouse)
            {
                MoveMenuRight();
                useMouse = false;
            }
            else if (input.IsMenuUp(ControllingPlayer) && !useMouse)
            {
                MoveMenuLeft();
            }
            else if (input.IsMenuDown(ControllingPlayer) && !useMouse)
            {
                MoveMenuRight();
            }
            else if (input.IsNewLeftMouseClick())
            {
                foreach (MenuButton button in MenuEntries)
                {
                    CheckButtonClick(input, button);
                }
            }
            else if (input.IsMenuSelect(ControllingPlayer, out playerIndex) && !useMouse)
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex) && !useMouse)
            {
                OnCancel(playerIndex);
            }

            for (int b = 0; b < menuEntries.Count; b++)
            {
                MenuButton button = menuEntries[b];

                button.IsHovering = false;

                CheckButtonHover(input, button);

                if (button.IsHovering)
                {
                    selectedEntry = b;
                }
            }

            // If the current mouse position doesn't equal the last, then our mouse is active!
            if (input.LastMouseState.X != mousePosition.X || input.LastMouseState.Y != mousePosition.Y)
            {
                useMouse = true;
            }

            if (!useMouse)
            {

            }
        }
コード例 #9
0
        public override void HandleInput(InputState input)
        {
            // We get our keyboard and gamepad states.
            currentKeyboardState = Keyboard.GetState();
            currentGamePadState = GamePad.GetState(PlayerIndex.One);

            // We check to see if the keyboard's space, enter, or escape keys, or the gamepad's A, B, or Start buttons are being pressed.
            if (currentKeyboardState.IsKeyDown(Keys.Space) || currentKeyboardState.IsKeyDown(Keys.Enter) || currentKeyboardState.IsKeyDown(Keys.Escape) ||
                currentGamePadState.IsButtonDown(Buttons.A) || currentGamePadState.IsButtonDown(Buttons.B) || currentGamePadState.IsButtonDown(Buttons.Start))
            {
                // If so, we tell the ScreenManager to get rid of this screen (nicely).
                ExitScreen();
            }
        }
コード例 #10
0
ファイル: GameScreen.cs プロジェクト: JoshuaKennedy/DarkHavoc
 /// <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) { }