/// <summary> /// Handles user input for all the local gamers in the session. Unlike most /// screens, which use the InputState class to combine input data from all /// gamepads, the lobby needs to individually mark specific players as ready, /// so it loops over all the local gamers and reads their inputs individually. /// </summary> public override void HandleInput(InputState input) { foreach (LocalNetworkGamer gamer in networkSession.LocalGamers) { PlayerIndex playerIndex = gamer.SignedInGamer.PlayerIndex; PlayerIndex unwantedOutput; if (input.IsMenuSelect(playerIndex, out unwantedOutput)) { HandleMenuSelect(gamer); } else if (input.IsMenuCancel(playerIndex, out unwantedOutput)) { HandleMenuCancel(gamer); } } }
/// <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)); ScreenManager.menu_enter.Play(); 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)); ScreenManager.menu_enter.Play(); ExitScreen(); } }
public override void HandleInput(InputState input) { // Move to the previous menu entry? if (input.IsMenuUp(ControllingPlayer)) { selectedEntry -= columns; if (selectedEntry < 0) selectedEntry = (selectedEntry + columns) + ( columns * 2); ScreenManager.menu_change.Play(); SetLevelNum(); } // Move to the next menu entry? if (input.IsMenuDown(ControllingPlayer)) { selectedEntry += columns; if (selectedEntry >= menuEntries.Count) selectedEntry = (selectedEntry - columns) - (columns * 2); ScreenManager.menu_change.Play(); SetLevelNum(); } // Move to the next menu entry? if (input.IsMenuRight(ControllingPlayer)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) selectedEntry = 0; ScreenManager.menu_change.Play(); SetLevelNum(); } if (input.IsMenuLeft(ControllingPlayer)) { selectedEntry--; if (selectedEntry < 0) selectedEntry = menuEntries.Count - 1; ScreenManager.menu_change.Play(); SetLevelNum(); } // 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> /// 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> /// Handles input for the specified player. In local game modes, this is called /// just once for the controlling player. In network modes, it can be called /// more than once if there are multiple profiles playing on the local machine. /// Returns true if we should continue to handle input for subsequent players, /// or false if this player has paused the game. /// </summary> bool HandlePlayerInput(InputState input, PlayerIndex playerIndex) { // Look up inputs for the specified player profile. KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[(int)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[(int)playerIndex]; if (input.IsPauseGame(playerIndex) || gamePadDisconnected) { if (sessionState == SessionState.Started) { ScreenManager.AddScreen(new PauseMenuScreen(networkSession), playerIndex); ScreenManager.menu_change.Play(); return false; } if (sessionState == SessionState.Complete) { Exit(); } } if (sessionState == SessionState.Started || sessionState == SessionState.Edit) { float timeDifference = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f; Player.HandleInput(timeDifference); PlayerIndex pI = PlayerIndex.Four; if (input.IsNewKeyPress(Keys.Space, playerIndex, out pI) || input.IsNewButtonPress(Buttons.RightTrigger, playerIndex, out pI)) { if (!parentGame.NormalMode) { if (TimeRemaining > 0) FireBullet(); } else FireBullet(); } float thumbRX = gamePadState.ThumbSticks.Right.X; if (thumbRX != 0) { Player.turretRotationValue -= 0.05f * thumbRX; float value = MathHelper.ToDegrees(Player.turretRotationValue); value = (float)Math.Round(value, 0); if (value % 10 == 0) { if (!RotateCue.IsPlaying) { RotateCue = parentGame.soundBank.GetCue("rotate"); AudioEmitter emmit = new AudioEmitter(); emmit.Position = Player.position; RotateCue.Apply3D(listener, emmit); RotateCue.Play(); } } } float thumbRY = gamePadState.ThumbSticks.Right.Y; if (thumbRY != 0) { Player.cannonRotationValue -= 0.05f * thumbRY; Player.cannonRotationValue = MathHelper.Clamp(Player.cannonRotationValue, MathHelper.ToRadians(-45), MathHelper.ToRadians(10)); float value = MathHelper.ToDegrees(Player.cannonRotationValue); value = (float)Math.Round(value, 0); if (value % 2 == 0 && value != -45 && value != 10) { if (!ElevateCue.IsPlaying) { ElevateCue = parentGame.soundBank.GetCue("elevate"); AudioEmitter emmit = new AudioEmitter(); emmit.Position = Player.position; ElevateCue.Apply3D(listener, emmit); ElevateCue.Play(); } } } float thumbLY = gamePadState.ThumbSticks.Left.Y; if (thumbLY != 0) { Player.Power += 0.01f * thumbLY; if (Player.Power > 1) Player.Power = 1f; else if (Player.Power < 0.1f) Player.Power = 0.1f; //power = 0 - 1 float value = Player.Power; value *= 100; //value = (float)Math.Round(value, 2); value = (float)Math.Floor(value); if (value % 5 == 0 && value != 100 && value != 10) { if (!PowerCue.IsPlaying) { PowerCue = parentGame.soundBank.GetCue("power"); PowerCue.SetVariable("PowerLevel", Player.Power); AudioEmitter emmit = new AudioEmitter(); emmit.Position = Player.position; PowerCue.Apply3D(listener, emmit); PowerCue.Play(); } } } MouseState mouseState = Mouse.GetState(); if (input.IsNewKeyPress(Keys.M, playerIndex, out pI)) CamIsFollow = (CamIsFollow) ? false : true; if (input.IsNewKeyPress(Keys.N, playerIndex, out pI)) sessionState = (sessionState == SessionState.Edit) ? SessionState.Started : SessionState.Edit; if (input.IsNewKeyPress(Keys.P, playerIndex, out pI)) NormalDrawing.BLEND += 1; if (sessionState == SessionState.Edit) { TerrEditor.HandleInput(); } prevMouseState = mouseState; } if (sessionState == SessionState.Complete) { if (input.IsMenuSelect(playerIndex, out playerIndex)) { Exit(); } } #region OLD PLAYER // Otherwise move the player position. Vector2 movement = Vector2.Zero; if (keyboardState.IsKeyDown(Keys.Left)) movement.X--; if (keyboardState.IsKeyDown(Keys.Right)) movement.X++; if (keyboardState.IsKeyDown(Keys.Up)) movement.Y--; if (keyboardState.IsKeyDown(Keys.Down)) movement.Y++; Vector2 thumbstick = gamePadState.ThumbSticks.Left; movement.X += thumbstick.X; movement.Y -= thumbstick.Y; if (movement.Length() > 1) movement.Normalize(); playerPosition += movement * 2; #endregion return true; }
/// <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"); if (ControllingPlayer.HasValue) { // In single player games, handle input for the controlling player. HandlePlayerInput(input, ControllingPlayer.Value); } else if (networkSession != null) { // In network game modes, handle input for all the // local players who are participating in the session. foreach (LocalNetworkGamer gamer in networkSession.LocalGamers) { if (!HandlePlayerInput(input, gamer.SignedInGamer.PlayerIndex)) break; } } }