public override void HandleInput(GameTime gameTime, InputState input) { // Test for the menuCancel action PlayerIndex player; if (menuCancel.Evaluate(input, ControllingPlayer, out player)) { OnCancel(); } // Read in our gestures foreach (GestureSample gesture in input.Gestures) { // If we have a tap if (gesture.GestureType == GestureType.Tap) { // Test the tap against the buttons until one of the buttons handles the tap foreach (Button b in menuButtons) { if (b.HandleTap(gesture.Position)) { break; } } } } base.HandleInput(gameTime, input); }
/// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else if (startAction.Evaluate(input, ControllingPlayer, out player)) { ScreenManager.AddScreen(DialogueScreen.InitializeDialogueBox(new Guid("129cfb6c-32de-11e2-8539-109adda800ea")), null); } }
/// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { #if WINDOWS_PHONE ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer); #else ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); #endif } else { } }
/// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; MouseState mouse = Mouse.GetState(); // 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[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { // bloom.Dispose(); bloom.Visible = false; ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { playerBody.detectInput(keyboardState, mouse, cam2D.Position, gameTime); } }
public override void HandleInput(float delta, InputState input) { #if !EDITOR if (input == null) { throw new ArgumentNullException("input"); } int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // Make the player go through the death animation so they know they've died. if (Player.Instance.PlayerState == PlayerState.Dead && Player.Instance.CurrentAnimation.Completed) { if (InputManager.Instance.Jump(true)) { LoadLevel(); } } } #endif }
/// <summary> /// Responds to user input, accepting or cancelling the message box. /// </summary> public override void HandleInput(GameTime gameTime, 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 (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex) || yesButton.IsClicked(Mouse.GetState())) { // Raise the accepted event, then exit the message box. if (Accepted != null) { Accepted(this, new PlayerIndexEventArgs(playerIndex)); } ExitScreen(); } else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex) || noButton.IsClicked(Mouse.GetState())) { // Raise the cancelled event, then exit the message box. if (Cancelled != null) { Cancelled(this, new PlayerIndexEventArgs(playerIndex)); } ExitScreen(); } }
public override void HandleInput(float delta, InputState input) { PlayerIndex playerIndex; float speed = 5; if (_inputContinue.Evaluate(input, ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } if (_moveUp.Evaluate(input, ControllingPlayer, out playerIndex)) { if (_position.Y < this.ScreenManager.GraphicsDevice.Viewport.Height * 0.2) { this._position.Y += speed; } } if (_moveDown.Evaluate(input, ControllingPlayer, out playerIndex)) { if (_position.Y + _texture.Height >= this.ScreenManager.GraphicsDevice.Viewport.Height * 0.8) { this._position.Y -= speed; } } }
/// <summary> /// Gère l'entrée de l'utilisateur. Appelée seulement lorsque cet écran /// est actif (contrairement à Update) /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Répertorie les entrées pour le profil de joueur actif int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; // Le jeu se met en pause si le joueur appuie sur le bouton pause, ou si // il déconnecte la manette active. Il faut donc garder une trace de si // une manette a déjà été branchée. On ne va pas mettre le jeu en pause si // il n'y a jamais eu de manette bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { // TODO : modifier la gestion des ship pour que les commandes soient déclenchées ici (philosophie de développement) } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { // For input tests 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; mouseHighlight(input, gameTime, this); // Move to the previous menu entry? if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } // if the entry is a blank then skip it while (menuEntries[selectedEntry].Text == "") { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } } } // Move to the next menu entry? if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } // if the entry is a blank then skip it while (menuEntries[selectedEntry].Text == "") { selectedEntry++; } } if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex)) { OnSelectEntry(selectedEntry, playerIndex); } else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }
public override void HandleInput(float delta, InputState input) { PlayerIndex playerIndex; // Move to the previous menu entry? if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } while (menuEntries[selectedEntry].ItemType == MenuEntryType.Separator || !menuEntries[selectedEntry].Enabled) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } } AudioManager.Instance.PlayCue("UI_Move_1", true); } // Move to the next menu entry? if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } while (menuEntries[selectedEntry].ItemType == MenuEntryType.Separator || !menuEntries[selectedEntry].Enabled) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } } AudioManager.Instance.PlayCue("UI_Move_1", true); } if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex)) { AudioManager.Instance.PlayCue("UI_Select_1", true); OnSelectEntry(selectedEntry, playerIndex); } else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } }
/// <summary> /// Gère l'entrée de l'utilisateur en changeant l'entrée sélectionnée, en la /// validant ou en quittant le menu /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { // Pour les tests d'entrée, on passe notre ControllingPlayer (membre de GameScreen dont on hérite) // qui est soit null (pour accepter l'entrée de n'importe quel joueur) ou un index spécifique. // Si on passe null, InputState nous retournera quel joueur a effectivement émit l'entrée. On le passe // ensuite à OnSelectEntry et OnCancel pour qu'ils sachent quel joueur les a ciblé PlayerIndex playerIndex; // Se déplacer vers l'entrée précédente ? if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } } // Se déplacer vers l'entrée suivante ? if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry++; if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } } if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex)) { OnSelectEntry(selectedEntry, playerIndex); } else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); } // Ajout perso : gestion de la souris oldms = ms; ms = Mouse.GetState(); for (int i = 0; i < menuEntries.Count; i++) { MenuEntry menuEntry = menuEntries[i]; if (new Rectangle((int)menuEntry.Position.X, (int)menuEntry.Position.Y - (int)menuEntry.Size.Y / 2, (int)menuEntry.Size.X, (int)menuEntry.Size.Y).Contains(new Point(ms.X, ms.Y))) { selectedEntry = i; if (ms.LeftButton == ButtonState.Pressed && oldms.LeftButton == ButtonState.Released) { OnSelectEntry(selectedEntry, playerIndex); } } } }
public override void HandleInput(float delta, InputState input) { PlayerIndex playerIndex; if (_skipScreen.Evaluate(input, ControllingPlayer, out playerIndex)) { this.ExitScreen(); } }
/// <summary> /// Responds to user input, changing the selected entry and accepting or cancelling /// the menu. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { PlayerIndex playerIndex; //Move to the previous menu entry? if (menuUp.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry--; if (!string.IsNullOrEmpty(selectionChangeSound)) { SoundManager.Play(selectionChangeSound); } if (selectedEntry < 0) { selectedEntry = menuEntries.Count - 1; } } //Move to the next menu entry? if (menuDown.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry++; if (!string.IsNullOrEmpty(selectionChangeSound)) { SoundManager.Play(selectionChangeSound); } if (selectedEntry >= menuEntries.Count) { selectedEntry = 0; } } if (menuSelect.Evaluate(input, ControllingPlayer, out playerIndex)) { OnSelectEntry(selectedEntry, playerIndex); if (!string.IsNullOrEmpty(selectionSound)) { SoundManager.Play(selectionSound); } } else if (menuCancel.Evaluate(input, ControllingPlayer, out playerIndex)) { OnCancel(playerIndex); if (!string.IsNullOrEmpty(cancelSound)) { SoundManager.Play(cancelSound); } } }
/// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; MouseState mouseState = Mouse.GetState(); // 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[playerIndex]; MC.Input(input, gameTime); PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { if (mouseState.LeftButton == ButtonState.Pressed) { Vector2 boxPos = (cam2D.Position / 64) + new Vector2(mouseState.X, mouseState.Y); Crates.Add(new Crate(content.Load <Texture2D>("Art/_box"), boxPos, world)); } if (keyboardState.IsKeyDown(Keys.A)) { cam2D.MoveCamera(new Vector2(-0.5f, 0)); } if (keyboardState.IsKeyDown(Keys.D)) { cam2D.MoveCamera(new Vector2(0.5f, 0)); } if (keyboardState.IsKeyDown(Keys.W)) { cam2D.MoveCamera(new Vector2(0, -0.5f)); } if (keyboardState.IsKeyDown(Keys.S)) { cam2D.MoveCamera(new Vector2(0, 0.5f)); } } }
public override void HandleInput(GameTime gameTime, InputState input) { base.HandleInput(gameTime, input); PlayerIndex idx; if (menuCancel.Evaluate(input, null, out idx)) { CallExit(); } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or pausing the <see cref="DialogueScreen"/>DialogueScreen</see>. /// </summary> public override void HandleInput(GameTime gameTime, InputState input) { // For input tests 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; // Move to the previous menu entry? if (upAction.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry--; if (selectedEntry < 0) { selectedEntry = responses.Count - 1; } } // Move to the next menu entry? if (downAction.Evaluate(input, ControllingPlayer, out playerIndex)) { selectedEntry++; if (selectedEntry >= responses.Count) { selectedEntry = 0; } } PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player)) { ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else if (selectAction.Evaluate(input, ControllingPlayer, out player)) { if (responses.Count != 0) { OnSelectEntry(selectedEntry); } else { if (Finished != null) { Finished(this, new PlayerIndexEventArgs(playerIndex)); } ExitScreen(); } } }
public override void HandleInput(GameTime gameTime, InputState input) { base.HandleInput(gameTime, input); PlayerIndex playerIndex; if (menuSelectBack.Evaluate(input, ControllingPlayer, out playerIndex)) { OnSelectEntryPrevious(selectedEntry, playerIndex); } }
public override void HandleInput(GameTime gameTime, InputState input) { // Test for the menuCancel action PlayerIndex player; if (menuCancel.Evaluate(input, ControllingPlayer, out player)) { OnCancel(); } base.HandleInput(gameTime, input); }
/// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { // bloom.Dispose(); bloom.Visible = false; ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { if (keyboardState.IsKeyDown(Keys.A) || keyboardState.IsKeyDown(Keys.Left)) { playerBody.playerBody.ApplyLinearImpulse(new Vector2(-1, 0)); } if (keyboardState.IsKeyDown(Keys.D) || keyboardState.IsKeyDown(Keys.Right)) { playerBody.playerBody.ApplyLinearImpulse(new Vector2(1, 0)); } if (keyboardState.IsKeyDown(Keys.S) || keyboardState.IsKeyDown(Keys.Down)) { playerBody.playerBody.ApplyLinearImpulse(new Vector2(0, 1)); } if (keyboardState.IsKeyDown(Keys.W) || keyboardState.IsKeyDown(Keys.Up)) { playerBody.playerBody.ApplyLinearImpulse(new Vector2(0, -1)); } } }
/// <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) { PlayerIndex player; foreach (GestureSample gesture in input.Gestures) { // If we have a tap if (gesture.GestureType == GestureType.Tap) { LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), new PhoneMainMenuScreen()); } } if (backToMenu.Evaluate(input, ControllingPlayer, out player)) { LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(), new PhoneMainMenuScreen()); } }
public override void HandleInput(GameTime gameTime, InputState input) { // Test for the menuCancel action PlayerIndex player; if (menuCancel.Evaluate(input, ControllingPlayer, out player)) { OnCancel(); } // Read in our gestures foreach (GestureSample gesture in input.Gestures) { // If we have a tap if (gesture.GestureType == GestureType.Tap) { nextLevelButton.HandleTap(gesture.Position); } } base.HandleInput(gameTime, input); }
/// <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. int playerIndex = (int)ControllingPlayer.Value; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player)) { ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer); } // The player lost a life or the game if (Player.isActive == false) { if (Player.Health > 0) { // The player lost a life ScreenManager.AddScreen(new LostLifeMenuScreen(), ControllingPlayer); Player.Reset(); currentTabPosition = Player.initPosition; // Reset the stopwatch stopwatch.Reset(); } if (Player.Health == 0) { // The player is gameover ScreenManager.AddScreen(new GameOverMenuScreen(), ControllingPlayer); Player.Initialize(); currentTabPosition = Player.initPosition; } } // The Player has won the Game if (Player.hasWon == true) { // Stop the stopwatch and give the elapsed time to the winnerScreen stopwatch.Stop(); timespan = stopwatch.Elapsed; ScreenManager.AddScreen(new winnerMenuScreen(Player.countTaps, Player.Health, currentLevel, timespan), ControllingPlayer); } if (Player.isActive == true) { // Loops through the inputs in queue // In this case it only looks for taps foreach (GestureSample gesture in input.Gestures) { if (gesture.GestureType == GestureType.Tap) { // Start stopwatch only if its the first tap if (Player.countTaps == 0) { stopwatch.Start(); } // Set the new tap position and calculate direction currentTabPosition = gesture.Position; // Subtract the players half-width and half-height ( for precisness reasons ) currentTabPosition.X -= Player.Width / 2; currentTabPosition.Y -= Player.Height / 2; //Recalculate the currentTap if it is out of range if (currentTabPosition.X < 0) { currentTabPosition.X = 0; } if (currentTabPosition.X > 775) { currentTabPosition.X = 775; } if (currentTabPosition.Y < 41) { currentTabPosition.Y = 41; } if (currentTabPosition.Y > 415) { currentTabPosition.Y = 415; } // Calculate the moving direction and normalize the vector to length 1 Player.movingDirection = currentTabPosition - Player.Position; Player.movingDirection.Normalize(); // Count Tap Player.countTaps += 1; } } } }
bool isRotated = false;//TODO : rename this variable appropriately , or create input manager? to handle "key pressed once" event? /// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { // bloom.Dispose(); bloom.Visible = false; ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { Dictionary <Tuple <Keys, Keys>, Vector2> dirMoves = new Dictionary <Tuple <Keys, Keys>, Vector2>() { { new Tuple <Keys, Keys> (Keys.A, Keys.Left), new Vector2(-.1f, 0) }, { new Tuple <Keys, Keys> (Keys.D, Keys.Right), new Vector2(.1f, 0) }, { new Tuple <Keys, Keys> (Keys.W, Keys.Up), new Vector2(0, -.1f) }, { new Tuple <Keys, Keys> (Keys.S, Keys.Down), new Vector2(0, .1f) } }; foreach (var k in dirMoves) { if (keyboardState.IsKeyDown(k.Key.Item1) || keyboardState.IsKeyDown(k.Key.Item2)) { cam2D.MoveCamera(k.Value); } } if (!isRotated && keyboardState.IsKeyDown(Keys.R)) { isRotated = true; if (assetRotation == 1.57f) { assetRotation = 0; } else { assetRotation = 1.57f; } } else if (keyboardState.IsKeyUp(Keys.R)) { isRotated = false; } if (keyboardState.IsKeyDown(Keys.Y)) { assetRotation += 0.1f; } if (keyboardState.IsKeyDown(Keys.T)) { assetRotation -= 0.1f; } if (keyboardState.IsKeyDown(Keys.T)) { assetRotation -= 0.1f; } if (keyboardState.IsKeyDown(Keys.Enter) && resetSave == false) { writeToFile(); resetSave = true; } if (keyboardState.IsKeyDown(Keys.LeftShift)) { resetSave = false; } } }
public void HandleInput(InputState input, PlayerIndex controllingPlayer) { #region Set up variables to use int playerIndex = (int)controllingPlayer; PlayerIndex player; int nextState = -1; #endregion #region Change Player State if (upActions.Evaluate(input, controllingPlayer, out player)) { if (leftActions.Evaluate(input, controllingPlayer, out player)) { nextState = UPLEFT; } else if (rightActions.Evaluate(input, controllingPlayer, out player)) { nextState = UPRIGHT; } else { nextState = UP; } } else if (downActions.Evaluate(input, controllingPlayer, out player)) { if (leftActions.Evaluate(input, controllingPlayer, out player)) { nextState = DOWNLEFT; } else if (rightActions.Evaluate(input, controllingPlayer, out player)) { nextState = DOWNRIGHT; } else { nextState = DOWN; } } else if (leftActions.Evaluate(input, controllingPlayer, out player)) { nextState = LEFT; } else if (rightActions.Evaluate(input, controllingPlayer, out player)) { nextState = RIGHT; } else { nextState = IDLE; } if (nextState != state) { state = nextState; switch (state) { default: activeSprite = 0; break; } ResetInactiveSprites(); } #endregion #region Try to fire bullets if (gunReloadTime <= 0 && fireActions.Evaluate(input, controllingPlayer, out player)) { bulletsFired.Add(new PlayerBullet(position, bounds)); gunReloadTime += 333.0f; } #endregion #region Set player Velocity velocity = new Vector2(); switch (state) { case UPLEFT: velocity = new Vector2(-HORIZONTAL_SPEED / 2.0f, -VERTICAL_SPEED / 2.0f); break; case UP: velocity = new Vector2(0, -VERTICAL_SPEED); break; case UPRIGHT: velocity = new Vector2(HORIZONTAL_SPEED / 2.0f, -VERTICAL_SPEED / 2.0f); break; case LEFT: velocity = new Vector2(-HORIZONTAL_SPEED, 0); break; case RIGHT: velocity = new Vector2(HORIZONTAL_SPEED, 0); break; case DOWNRIGHT: velocity = new Vector2(HORIZONTAL_SPEED / 2.0f, VERTICAL_SPEED / 2.0f); break; case DOWN: velocity = new Vector2(0, VERTICAL_SPEED); break; case DOWNLEFT: velocity = new Vector2(-HORIZONTAL_SPEED / 2.0f, VERTICAL_SPEED / 2.0f); break; default: velocity = new Vector2(0, 0); break; } #endregion #region Adjust Time if (slowTimeActions.Evaluate(input, controllingPlayer, out player) && chaosDriveFuel > 0 && driveReloadTime <= 0) { timeAdjustment = 0.5f; } else if (accelTimeActions.Evaluate(input, controllingPlayer, out player) && chaosDriveFuel > 0 && driveReloadTime <= 0) { timeAdjustment = 2.0f; } else { timeAdjustment = 1.0f; } #endregion }
/// <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"); } //Sets previous camera position to the last position it was //(only when panning is not initiated) _camera.PreviousCameraPosition = _averagePlayerPosition; _averagePlayerPosition = Vector2.Zero; int NumberOfActivePlayers = 0; for (int playerIndex = 0; playerIndex < playerList.Count; playerIndex++) { // Look up inputs for the active player profile. // sets the index by default to player one. PlayerIndex pI = PlayerIndex.One; switch (playerIndex) { case 0: pI = PlayerIndex.One; break; case 1: pI = PlayerIndex.Two; break; case 2: pI = PlayerIndex.Three; break; case 3: pI = PlayerIndex.Four; break; } KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; //Reset the level if (resetAction.Evaluate(input, pI, out player)) { ResetLevel(); } //Toggle the collision markers on and off if (playerIndex == 0) { if (toggleCollisionVisibility.Evaluate(input, pI, out player)) { foreach (CollisionSurface c in _layers[_layerDictionary["c"]].Sprites) { c.Visible = !c.Visible; } } } //If the game is paused, add the pause screen if (pauseAction.Evaluate(input, pI, out player) || gamePadDisconnected) { ScreenManager.AddScreen(new PauseMenuScreen(), pI); } else { if (stunPlayers.Evaluate(input, pI, out player)) { playerList[playerIndex].IsStunned = true; } // Otherwise update the player position. playerList[playerIndex].Update(gameTime, input, _layers[_layerDictionary["c"]].Sprites, _layers[_layerDictionary["interactive"]].Sprites); } //Gets the bounds of the screen to check whether the player is within them Rectangle screenBounds = new Rectangle((int)_camera.Position.X, (int)_camera.Position.Y, (int)(BaseScreenSize.X / _camera.Zoom), (int)(BaseScreenSize.Y / _camera.Zoom)); if (!playerList[playerIndex].BoundingBox().Intersects(screenBounds)) { //If the player is outside the bounds of the screen and still alive, kill them. if (playerList[playerIndex].IsAlive) { //Initiate the camera pan to the new average position _camera.SlideCamera = true; playerList[playerIndex].IsAlive = false; } } //If the player is alive, then add their position to the average if (playerList[playerIndex].IsAlive) { _averagePlayerPosition += playerList[playerIndex].Position; NumberOfActivePlayers++; } } //Find the average screen position of all active players (dead players are inactive). _averagePlayerPosition.X = _averagePlayerPosition.X / NumberOfActivePlayers; _averagePlayerPosition.Y = _averagePlayerPosition.Y / NumberOfActivePlayers; //Move the camera to look at this position _camera.LookAt(_averagePlayerPosition, BaseScreenSize); if (NumberOfActivePlayers == 0) { ResetLevel(); } }
public override void HandleInput(GameTime gameTime, InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { bloom.Visible = false; ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); } else { if (keyboardState.IsKeyDown(Keys.A) || gamePadState.Buttons.A == ButtonState.Pressed) { if (levelFrom == 1) { ExitScreen(); bloom.Visible = false; LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new GameplayScreen()); } else if (levelFrom == 2) { ExitScreen(); bloom.Visible = false; LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new level2Screen()); } else if (levelFrom == 3) { ExitScreen(); bloom.Visible = false; LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new level3Screen()); } else if (levelFrom == 0) { ExitScreen(); bloom.Visible = false; LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new TutLevel1()); } } // enter or a is continue // b or esc is back ect } }
/// <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. int playerIndex = (int)(ControllingPlayer ?? 0); KeyboardState keyboardState = input.CurrentKeyboardStates; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (PauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { Machine.Paused = true; UnpauseOnActivation = true; ScreenManager.AddScreen(new MainMenuScreen(ScreenManager), ControllingPlayer); } Keyboard.GetState(); if (Keyboard.HasBeenPressed(Keys.Space)) { Machine.Paused = !Machine.Paused; } if (Keyboard.HasBeenPressed(Keys.Enter)) { MathboxRenderer.PauseOnNextRender = true; Machine.Paused = false; } if (Keyboard.HasBeenPressed(Keys.Tab)) { Settings.TestSwitch = !Settings.TestSwitch; } if (Keyboard.HasBeenPressed(Keys.F3)) { Machine.Reset(Emulation.Machine.RESET_TYPE.USER); } if (Keyboard.HasBeenPressed(Keys.F7)) { if (Keyboard.IsPressed(Keys.LeftShift) || Keyboard.IsPressed(Keys.RightShift)) { // save state using (FileStream stream = new FileStream("irobot.sav", FileMode.Create)) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, Machine); stream.Close(); } } else { // load state using (FileStream stream = new FileStream("irobot.sav", FileMode.Open)) { // IFormatter formatter = new BinaryFormatter(); // Machine = (Machine)formatter.Deserialize(stream); // stream.Close(); } } } if (Keyboard.HasBeenPressed(Keys.F10)) { Settings.SpeedThrottle = !Settings.SpeedThrottle; } }
public override void HandleInput(GameTime gameTime, InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Look up inputs for the active player profile. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { #if WINDOWS_PHONE EngineInstance.Pause(); ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer); #else ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); #endif } else { // If Accelerometer is off, touch input will be used if (ScreenManager.enableAccelerometer == false && ScreenManager.enableAnimation == false) { //// Otherwise move the player position. Vector2 movement = Vector2.Zero; if (input.TouchState.Count > 0) { Vector2 touchPosition = input.TouchState[0].Position; //distance = new Vector2(((touchPosition.X - playerPosition.X) - 20), ((touchPosition.Y - playerPosition.Y) - 50)); distance = new Vector2(((touchPosition.X - playerPosition.X) - 20), 0); movement = distance / 8; } playerPosition += movement; playerRect.X += Convert.ToInt32(movement.X); // Prevent player from moving off the road if (playerPosition.X <= 72) { playerPosition.X = 72; distance.X = 0; } else if (playerPosition.X + carWidth >= 300) { playerPosition.X = 300 - carWidth; distance.X = 0; } // } } }
/// <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. int playerIndex = (int)ControllingPlayer.Value; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState 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! bool gamePadDisconnected = !gamePadState.IsConnected && input.GamePadWasConnected[playerIndex]; PlayerIndex player; if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected) { #if WINDOWS_PHONE ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer); #else ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer); #endif } else { // 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 (input.TouchState.Count > 0) { Vector2 touchPosition = input.TouchState[0].Position; Vector2 direction = touchPosition - playerPosition; direction.Normalize(); movement += direction; } if (movement.Length() > 1) { movement.Normalize(); } playerPosition += movement * 8f; } }
/// <summary> /// Gets player horizontal movement and jump commands from input. /// </summary> private void GetInput(GameTime gameTime, InputState input) { int thisPlayer = (int)playerIndex; GamePadState gamePadState = input.CurrentGamePadStates[thisPlayer]; if (!IsStunned) { //Get analog horizontal movement. movement = gamePadState.ThumbSticks.Left.X * MoveStickScale; //Ignore small movements to prevent running in place. if (Math.Abs(movement) < 0.5f) { movement = 0.0f; } // If any digital horizontal movement input is found, override the analog movement. PlayerIndex player; if (moveLeft.Evaluate(input, playerIndex, out player)) { movement = -1.0f; } else if (moveRight.Evaluate(input, playerIndex, out player)) { movement = 1.0f; } //Change animation based on movement input. if (movement < 0) { if (Animation != "Left") { Animation = "Left"; } } else if (movement > 0) { if (Animation != "Right") { Animation = "Right"; } } else { if (!Animation.Contains("Idle")) { if (Animation.Contains("Left")) { Animation = "LeftIdle"; } else { Animation = "RightIdle"; } } } //if( !apexReached) wantsToJump = jump.Evaluate(input, playerIndex, out player); isSprinting = sprint.Evaluate(input, playerIndex, out player); isCrouching = crouch.Evaluate(input, playerIndex, out player); /*if (!wasJumping) * { * if ((isJumping && jumpTime == 0.0f) && !IsOnGround) * isGliding = true; * else * isGliding = false; * }*/ //if( IsFalling & !wasJumping & !IsOnGround) //isGliding = jump.Evaluate(input, playerIndex, out player); } }