public override void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime) { base.HandleInput(gameScreen, input, gameTime); //if (gameScreen.Console != null && gameScreen.Console.Active) // return; PlayerIndex p; Animate = false; if (input.IsKeyPressed(Keys.A, PlayerIndex.One, out p)) { Move(Direction.Left); } if (input.IsKeyPressed(Keys.W, PlayerIndex.One, out p) && !jumping) { Move(Direction.Up); jumping = true; } //else if (input.IsKeyPressed(Keys.S, PlayerIndex.One, out p)) //{ // Move(Direction.Down); //} if (input.IsKeyPressed(Keys.D, PlayerIndex.One, out p)) { Move(Direction.Right); } else { //BodyPart.LinearVelocity = Vector2.Zero; } }
public override void OnInput(InputState input) { Keys[] pressedKeys = input.NewPressedKeys().ToArray(); for (int i = pressedKeys.Length - 1; i >= 0; i--) { Keys pressedKey = pressedKeys[i]; int pressedKeyNum = (int)pressedKey; if (pressedKey >= Keys.A && pressedKey <= Keys.Z) { Value += (char)((input.IsKeyPressed(Keys.LeftShift) || input.IsKeyPressed(Keys.RightShift)) ? pressedKeyNum : pressedKeyNum + 32); } else if (pressedKey == Keys.Space) Value += " "; else if (pressedKey == Keys.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1); //if (input.Mapping.Chars().ContainsKey(pressedKey)) Value += input.IsKeyPress(input.Mapping.Shift) ? input.Mapping.Chars()[pressedKey] : (char)(input.Mapping.Chars()[pressedKey] + 32); //else if (input.Mapping.Numbers().ContainsKey(pressedKey)) Value += input.Mapping.Numbers()[pressedKey].ToString(); //else if (pressedKey == input.Mapping.Hyphen || pressedKey == Key.Minus) Value += input.IsKeyPress(Key.ShiftLeft) ? "_" : "-"; //else if (pressedKey == input.Mapping.Point) Value += input.IsKeyPress(Key.ShiftLeft) ? ":" : "."; //else if (pressedKey == input.Mapping.Comma) Value += input.IsKeyPress(Key.ShiftLeft) ? ";" : ","; //else if (pressedKey == input.Mapping.Space) Value += " "; //else if (pressedKey == input.Mapping.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1); } base.OnInput(input); }
private void HandlePlayerInput(GameTime gameTime, InputState input, PlayerIndex playerIndex) { Ship ship, enemyShip; if (playerIndex == ControllingPlayer) { ship = shipOne; enemyShip = shipTwo; } else { ship = shipTwo; enemyShip = shipOne; } PlayerIndex dummy; #if XBOX360 if (input.IsButtonPressed(Buttons.A, playerIndex, out dummy) || input.IsKeyPressed(Keys.F, playerIndex, out dummy)) { ship.FireBullet(ScreenManager, enemyShip); } if (input.IsButtonPressed(Buttons.B, playerIndex, out dummy) || input.IsKeyPressed(Keys.G, playerIndex, out dummy)) { ship.FireMissile(ScreenManager, enemyShip); } #else #endif }
/// <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(GameTime gameTime, InputState input) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. var playerIndex = (int) ControllingPlayer.Value; var keyboardState = input.CurrentKeyboardStates[playerIndex]; playerIndex = input.CurrentGamePadStates[playerIndex + 4].IsConnected ? playerIndex + 4 : playerIndex; var gamePadState = input.CurrentGamePadStates[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! var gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (_pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Otherwise handle input. #region temporary keybord controls if (keyboardState.IsKeyDown(Keys.Home)) _camera.Pitch += .01f; if (keyboardState.IsKeyDown(Keys.End)) _camera.Pitch -= .01f; if (keyboardState.IsKeyDown(Keys.PageDown)) _camera.Translate(new Vector3(0, -.02f, 0)); if (keyboardState.IsKeyDown(Keys.PageUp)) _camera.Translate(new Vector3(0, .02f, 0)); // temporary camera controls if (input.IsKeyPressed(Keys.I, null, out player)) _camera.Translate(Vector3.UnitZ*-0.1f); if (input.IsKeyPressed(Keys.K, null, out player)) _camera.Translate(Vector3.UnitZ*0.1f); if (input.IsKeyPressed(Keys.J, null, out player)) _camera.Translate(Vector3.UnitX*-0.1f); if (input.IsKeyPressed(Keys.L, null, out player)) _camera.Translate(Vector3.UnitX*0.1f); // player 1 temporary controls)););) if (input.IsNewKeyPress(Keys.W, null, out player)) _puzzleBoard1.Up(); if (input.IsNewKeyPress(Keys.S, null, out player)) _puzzleBoard1.Down(); if (input.IsNewKeyPress(Keys.A, null, out player)) _puzzleBoard1.Left(); if (input.IsNewKeyPress(Keys.D, null, out player)) _puzzleBoard1.Right(); if (input.IsNewKeyPress(Keys.Q, null, out player)) _puzzleBoard1.Select(); if (input.IsNewKeyPress(Keys.E, null, out player)) _puzzleBoard1.Accept(); if (input.IsNewKeyPress(Keys.R, null, out player)) _puzzleBoard1.Randomize(); // player 2 temporary controls if (input.IsNewKeyPress(Keys.Up, null, out player)) _puzzleBoard2.Up(); if (input.IsNewKeyPress(Keys.Down, null, out player)) _puzzleBoard2.Down(); if (input.IsNewKeyPress(Keys.Left, null, out player)) _puzzleBoard2.Left(); if (input.IsNewKeyPress(Keys.Right, null, out player)) _puzzleBoard2.Right(); if (input.IsNewKeyPress(Keys.RightControl, null, out player)) _puzzleBoard2.Select(); if (input.IsNewKeyPress(Keys.Enter, null, out player)) _puzzleBoard2.Accept(); if (input.IsNewKeyPress(Keys.Back, null, out player)) _puzzleBoard2.Randomize(); if (keyboardState.IsKeyDown(Keys.Z)) _camera.Yaw += .01f; if (keyboardState.IsKeyDown(Keys.X)) _camera.Yaw -= .01f; // DEBUG, remove ASAP if (input.IsNewKeyPress(Keys.D1, null, out player)) { SpawnUnit("menele_ranged", _player1, Vector3.Zero); } if (input.IsNewKeyPress(Keys.D2, null, out player)) { SpawnUnit("menel_ram", _player1, Vector3.Zero); } if (input.IsNewKeyPress(Keys.D3, null, out player)) { SpawnUnit("menele_ranged", _player2, Vector3.Zero); } if (input.IsNewKeyPress(Keys.D4, null, out player)) { SpawnUnit("menel_infantry", _player2, Vector3.Zero); } if (input.IsNewKeyPress(Keys.D5, null, out player)) { SpawnUnit("menel_boar", _player1, 6*Vector3.UnitY); } if (input.IsNewKeyPress(Keys.D6, null, out player)) { SpawnUnit("menel_boar", _player2, 6*Vector3.UnitY); } if (input.IsNewKeyPress(Keys.D7, null, out player)) { SpawnUnit("menel_infantry", _player2, Vector3.Zero); } if (input.IsNewKeyPress(Keys.D8, null, out player)) { SpawnUnit("menel_ram", _player2, Vector3.Zero); } // END OF DEBUG if (keyboardState.IsKeyDown(Keys.Delete)) _sceneRenderer.RenderShadows = !_sceneRenderer.RenderShadows; #endregion #region Gamepad controls Vector2 tsPos = gamePadState.ThumbSticks.Left; if (Math.Abs(tsPos.X) > 0.1f || Math.Abs(tsPos.Y) > 0.1f) _camera.Translate(new Vector3(tsPos, 0.0f)); if (gamePadState.IsButtonDown(Buttons.DPadUp)) _puzzleBoard1.Up(); if (gamePadState.IsButtonDown(Buttons.DPadDown)) _puzzleBoard1.Down(); if (gamePadState.IsButtonDown(Buttons.DPadLeft)) _puzzleBoard1.Left(); if (gamePadState.IsButtonDown(Buttons.DPadRight)) _puzzleBoard1.Right(); if (gamePadState.IsButtonDown(Buttons.X)) _puzzleBoard1.Select(); if (gamePadState.IsButtonDown(Buttons.Y)) _puzzleBoard1.Accept(); if (gamePadState.IsButtonDown(Buttons.A)) _puzzleBoard1.Randomize(); #endregion _simulation.Tick(gameTime); } }