/// <summary> /// Input helper method provided by GameScreen. Packages up the various input /// values for ease of use /// </summary> /// <param name="input">The state of the gamepads</param> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { foreach (GameScreen screen in ScreenManager.GetScreens()) screen.ExitScreen(); CollisionManager.ClearAll(); ScreenManager.AddScreen(new BackgroundScreen()); ScreenManager.AddScreen(new MainMenuScreen()); } }
public override void HandleInput(InputState input) { base.HandleInput(input); /// <summary> /// Read Touchscreen input /// </summary> /// <remarks> /// The base HandleInput has already populated lastTouchInput /// </remarks> if (lastTouchInput.Count > 0) { foreach (var touch in lastTouchInput) { switch (touch.State) { case TouchLocationState.Pressed: if (topPaddleTouchId == -1 && touch.Position.Y < topPaddle.Position.Y + topPaddle.Height && touch.Position.X > topPaddle.Position.X - 20 && touch.Position.X < topPaddle.Position.X + topPaddle.Width + 20) { topPaddleTouch = touch; topPaddleTouchId = touch.Id; //TODO: remove touch from lastTouchInput? } break; case TouchLocationState.Moved: if (touch.Id == topPaddleTouchId) { topPaddleTouch = touch; } break; case TouchLocationState.Released: if (touch.Id == topPaddleTouchId) { topPaddleTouchId = -1; } break; default: break; } } } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> /// public override void HandleInput(InputState input) { //TouchCollection touchState = TouchPanel.GetState(); bool touchDetected = false; Vector2 touchPosition = new Vector2(); //interpert touch screen presses foreach (TouchLocation location in input.TouchState) { switch (location.State) { case TouchLocationState.Pressed: touchDetected = true; touchPosition = location.Position; break; case TouchLocationState.Moved: break; case TouchLocationState.Released: break; } } if (touchDetected) { foreach (MenuEntry menuEntry in menuEntries) { Rectangle touchRect = new Rectangle((int)touchPosition.X - 5, (int)touchPosition.Y - 5, 10, 10); if (menuEntry.EntryPosition.Intersects(touchRect)) menuEntry.OnSelectEntry(); } } // Move to the previous menu entry? if (input.MenuUp) { selectedEntry--; if (selectedEntry < 0) selectedEntry = menuEntries.Count - 1; } // Move to the next menu entry? if (input.MenuDown) { selectedEntry++; if (selectedEntry >= menuEntries.Count) selectedEntry = 0; } // Accept or cancel the menu? if (input.MenuSelect) { OnSelectEntry(selectedEntry); } else if (input.MenuCancel) { OnCancel(); } }
/// <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> /// Input helper method provided by GameScreen. Packages up the various input /// values for ease of use /// </summary> /// <param name="input">The state of the gamepads</param> public override void HandleInput(InputState input) { if (input == null) throw new ArgumentNullException("input"); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { foreach (GameScreen screen in ScreenManager.GetScreens()) screen.ExitScreen(); CollisionManager.ClearAll(); ScreenManager.AddScreen(new BackgroundScreen()); ScreenManager.AddScreen(new MainMenuScreen()); } //if (input.IsPauseGame(null)) //{ // PauseCurrentGame(); //} /// Read Touchscreen input /// For now, add all "Pressed" and "Moved" events to lastTouchInput if (input.TouchState.Count > 0) { lastTouchInput = new List<TouchLocation>(); foreach (var touch in input.TouchState) { switch (touch.State) { case TouchLocationState.Pressed: if (bottomPaddleTouchId == -1 && touch.Position.Y > bottomPaddle.Position.Y && touch.Position.X > bottomPaddle.Position.X - 20 && touch.Position.X < bottomPaddle.Position.X + bottomPaddle.Width + 20) { bottomPaddleTouch = touch; bottomPaddleTouchId = touch.Id; } else { lastTouchInput.Add(touch); } break; case TouchLocationState.Moved: if (touch.Id == bottomPaddleTouchId) { bottomPaddleTouch = touch; } else { lastTouchInput.Add(touch); } break; case TouchLocationState.Released: if (touch.Id == bottomPaddleTouchId) { bottomPaddleTouchId = -1; } else { lastTouchInput.Add(touch); } break; default: break; } } } /// Read Accelerometer input /// (use it to update powerups) float movement = 0.0f; if (accelState != null) { if (Math.Abs(accelState.X) > 0.10f) { if (accelState.X > 0.0f) movement = 10.0f; else movement = -10.0f; } } // TODO: use this movement to update powerups /// Read keyboard input /// (use it for debugging) KeyboardState keyState = Keyboard.GetState(); lastKeyInput = new List<Keys>(); //For default, bottom paddle movement if (keyState.IsKeyDown(Keys.Left)) { lastKeyInput.Add(Keys.Left); } if (keyState.IsKeyDown(Keys.Right)) { lastKeyInput.Add(Keys.Right); } //For multitouch, top paddle movement if (keyState.IsKeyDown(Keys.F)) { lastKeyInput.Add(Keys.F); } if (keyState.IsKeyDown(Keys.D)) { lastKeyInput.Add(Keys.D); } }