public override void HandleInput(InputState input) { if (player.currentKeyboardState.IsKeyDown(Keys.P) && !player.previousKeyboardState.IsKeyDown(Keys.P)) { paused = !paused; ScreenManager.AddScreen(new PauseScreen(this)); } HandleCollisions(); }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(InputState input) { // we cancel the current menu screen if the user presses the back button PlayerIndex player; if (input.IsNewButtonPress(Buttons.Back, new PlayerIndex(), out player)) { OnCancel(player); } // look for any taps that occurred and select any entries that were tapped // convert the position to a Point that we can test against a Rectangle //Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y); Point mouseLocation = new Point(Mouse.GetState().X, Mouse.GetState().Y); // iterate the entries to see if any were tapped for (int i = 0; i < menuEntries.Count; i++) { MenuEntry menuEntry = menuEntries[i]; String output = ""; if (GetMenuEntryHitBounds(menuEntry).Contains(mouseLocation) && Mouse.GetState().LeftButton==ButtonState.Pressed) { // select the entry. since gestures are only available on Windows Phone, // we can safely pass PlayerIndex.One to all entries since there is only // one player on Windows Phone. output = menuEntry.Text; System.Diagnostics.Debug.WriteLine(output); menuEntry.OnSelectEntry(PlayerIndex.One); } } }
public void HandleInput(InputState input) { int elapsed = gameTime.ElapsedGameTime.Milliseconds; previousKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); idle = true; if (currentKeyboardState.IsKeyDown(Keys.Left)) { if (playerState.velocity.X > -0.2f) playerState.velocity.X -= 0.004f*elapsed; playerAction = PlayerAction.WalkingLeft; idle = false; facingRight = false; } if (currentKeyboardState.IsKeyDown(Keys.Right)) { if (playerState.velocity.X < 0.2f) playerState.velocity.X += 0.004f*elapsed; playerAction = PlayerAction.WalkingRight; idle = false; facingRight = true; } if (currentKeyboardState.IsKeyDown(Keys.Up)) { if (playerState.velocity.Y > -0.5f) playerState.velocity.Y += -0.005f*elapsed; //playerAction = PlayerAction.Jumping; playerState.rising = true; idle = false; } else { playerState.rising = false; } if (currentKeyboardState.IsKeyDown(Keys.Down)) { //playerState.velocity.Y += playerMoveSpeed; //playerAction = PlayerAction.Falling; idle = false; } if (currentKeyboardState.IsKeyDown(Keys.Z) && !previousKeyboardState.IsKeyDown(Keys.Z)) { lanternToggle(); } if (currentKeyboardState.IsKeyDown(Keys.X) && !previousKeyboardState.IsKeyDown(Keys.X)) { if (playerState.onGround) jump(); } if (idle) { if (facingRight) playerAction = PlayerAction.IdleRight; else playerAction = PlayerAction.IdleLeft; } }
public override void HandleInput(InputState input) { currentKeyboardState = Keyboard.GetState(); if (currentKeyboardState.IsKeyDown(Keys.P) && !previousKeyboardState.IsKeyDown(Keys.P)) ExitScreen(); previousKeyboardState = currentKeyboardState; }