public void HandleInput(InputState input, int index) { KeyboardState keyboardState = input.CurrentKeyboardStates[index]; GamePadState gamePadState = input.CurrentGamePadStates[index]; Vector2 direction = Vector2.Zero; // XBox controller input. direction.X += gamePadState.ThumbSticks.Left.X; direction.Y -= gamePadState.ThumbSticks.Left.Y; // keyboard input for development purposes. if (keyboardState.IsKeyDown(index == 0 ? Keys.A : Keys.Left)) direction.X--; if (keyboardState.IsKeyDown(index == 0 ? Keys.D : Keys.Right)) direction.X++; if (keyboardState.IsKeyDown(index == 0 ? Keys.W : Keys.Up)) direction.Y--; if (keyboardState.IsKeyDown(index == 0 ? Keys.S : Keys.Down)) direction.Y++; // Normalization only necessary for keyboard input. if (direction.Length() > 1.0f) { direction.Normalize(); } if (direction.Length() == 0) { this.IsMoving = false; } else { this.Direction = direction; this.IsMoving = true; } if (this.Direction.Y > 0) this.Body.X = 300 + ghostOffset; else if (this.Direction.Y < 0) this.Body.X = 100 + ghostOffset; else if (this.Direction.X < 0) this.Body.X = 200 + ghostOffset; else this.Body.X = ghostOffset; //fire ze missiles if (gamePadState.Buttons.A == ButtonState.Pressed) { this.firing = true; } else if (keyboardState.IsKeyDown(index == 0 ? Keys.Space : Keys.Enter)) this.firing = true; else this.firing = false; }
public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } int playerIndex = (int) this.ControllingPlayer.Value; bool gamePadDisconnected = !input.CurrentGamePadStates[playerIndex].IsConnected && input.GamePadWasConnected[playerIndex]; ; if (input.IsPauseGame(this.ControllingPlayer) || gamePadDisconnected) { this.ScreenManager.AddScreen(new PauseMenuScreen(), this.ControllingPlayer); } else { for (int i = 0; i < this.players.Count; i++) { this.players[i].HandleInput(input, i); } } }
/// <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> /// 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) { }