/// <summary> /// Exit the screen after a tap gesture /// </summary> /// <param name="gameTime"> /// The game Time. /// </param> /// <param name="input"> Input state /// </param> public override void HandleInput(GameTime gameTime, InputState input) { if (!isLoading) { if (input.Gestures.Count > 0) { if (input.Gestures[0].GestureType == GestureType.Tap) { LoadResources(); } } } base.HandleInput(gameTime, input); }
/// <summary> /// Handle any input from the user /// </summary> /// <param name="gameTime"></param> /// <param name="input"></param> public override void HandleInput(GameTime gameTime, InputState input) { if (input == null) throw new ArgumentNullException("input"); // Return to the main menu when a tap gesture is recognized if (input.Gestures.Count > 0) { GestureSample sample = input.Gestures[0]; if (sample.GestureType == GestureType.Tap) { StartNewLevelOrExit(input); input.Gestures.Clear(); } } base.HandleInput(gameTime, input); }
/// <summary> /// Handles user input as a part of screen logic update. /// </summary> /// <param name="gameTime">Game time information.</param> /// <param name="input">Input information.</param> public override void HandleInput(GameTime gameTime, InputState input) { if (input == null) { throw new ArgumentNullException("input"); } if (input.IsPauseGame(null)) { Exit(); } // Return to the main menu when a tep gesture is recognized if (input.Gestures.Count > 0) { GestureSample sample = input.Gestures[0]; if (sample.GestureType == GestureType.Tap) { Exit(); input.Gestures.Clear(); } } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput(GameTime gameTime,InputState input) { // we cancel the current menu screen if the user presses the back button PlayerIndex player; if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player)) { OnCancel(player); } // look for any taps that occurred and select any entries that were tapped foreach (GestureSample gesture in input.Gestures) { if (gesture.GestureType == GestureType.Tap) { // 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); // iterate the entries to see if any were tapped for (int i = 0; i < menuEntries.Count; i++) { MenuEntry menuEntry = menuEntries[i]; if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation)) { // 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. OnSelectEntry(i, PlayerIndex.One); } } } } }
/// <summary> /// Handle the player's input. /// </summary> /// <param name="gameTime"> /// The game Time. /// </param> /// <param name="input"> /// gamepad input state /// </param> public override void HandleInput(GameTime gameTime, InputState input) { if (IsActive) { if (input == null) { throw new ArgumentNullException("input"); } VirtualThumbsticks.Update(input); if (input.IsPauseGame(null)) { pauseCurrentGame(); } } if (input.TouchState.Count > 0) { foreach (TouchLocation touch in input.TouchState) { lastTouchPosition = touch.Position; } } isSmokebuttonClicked = false; PlayerIndex player; // If there was any touch if (VirtualThumbsticks.RightThumbstickCenter.HasValue) { // Button BodyRectangle Rectangle buttonRectangle = new Rectangle((int)smokeButtonPosition.X, (int)smokeButtonPosition.Y, smokeButton.Width / 2, smokeButton.Height); // Touch BodyRectangle Rectangle touchRectangle = new Rectangle((int)VirtualThumbsticks.RightThumbstickCenter.Value.X, (int)VirtualThumbsticks.RightThumbstickCenter.Value.Y, 1, 1); // If the touch is in the button if (buttonRectangle.Contains(touchRectangle)) { isSmokebuttonClicked = true; } } if (input.IsKeyDown(Keys.Space, ControllingPlayer, out player)) { isSmokebuttonClicked = true; } if (input.Gestures.Count > 0) { if (isLevelEnd) { if (input.Gestures[0].GestureType == GestureType.Tap) { userTapToExit = true; } } } }
/// <summary> /// Updates the virtual thumbsticks based on current touch state. This must be called every frame. /// </summary> public static void Update(InputState input) { TouchLocation? leftTouch = null, rightTouch = null; TouchCollection touches = input.TouchState; // Examine all the touches to convert them to virtual dpad positions. Note that the 'touches' // collection is the set of all touches at this instant, not a sequence of events. The only // sequential information we have access to is the previous location for of each touch. foreach (TouchLocation touch in touches) { if (touch.Id == leftId) { // This is a motion of a left-stick touch that we're already tracking leftTouch = touch; continue; } if (touch.Id == rightId) { // This is a motion of a right-stick touch that we're already tracking rightTouch = touch; continue; } // We didn't continue an existing thumbstick gesture; see if we can start a new one. // // We'll use the previous touch position if possible, to get as close as possible to where // the gesture actually began. TouchLocation earliestTouch; if (!touch.TryGetPreviousLocation(out earliestTouch)) { earliestTouch = touch; } if (leftId == -1) { // if we are not currently tracking a left thumbstick and this touch is on the left // half of the screen, start tracking this touch as our left stick if (earliestTouch.Position.X < TouchPanel.DisplayWidth/2) { leftTouch = earliestTouch; continue; } } if (rightId == -1) { // if we are not currently tracking a right thumbstick and this touch is on the right // half of the screen, start tracking this touch as our right stick if (earliestTouch.Position.X >= TouchPanel.DisplayWidth/2) { rightTouch = earliestTouch; continue; } } } // if we have a left touch if (leftTouch.HasValue) { // if we have no center, this position is our center if (!LeftThumbstickCenter.HasValue) { LeftThumbstickCenter = leftTouch.Value.Position; } // save the position of the touch leftPosition = leftTouch.Value.Position; // save the ID of the touch leftId = leftTouch.Value.Id; } else { // otherwise reset our values to not track any touches // for the left thumbstick LeftThumbstickCenter = null; leftId = -1; } // if we have a right touch if (rightTouch.HasValue) { // if we have no center, this position is our center if (!RightThumbstickCenter.HasValue) { RightThumbstickCenter = rightTouch.Value.Position; } // save the position of the touch rightPosition = rightTouch.Value.Position; // save the ID of the touch rightId = rightTouch.Value.Id; } else { // otherwise reset our values to not track any touches // for the right thumbstick RightThumbstickCenter = null; rightId = -1; } }
/// <summary> /// Starts new level or exit to High Score /// </summary> /// <param name="input"></param> private void StartNewLevelOrExit(InputState input) { // If there is no next level - go to high score screen if (!difficultyMode.HasValue) { ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null); ScreenManager.AddScreen(new HighScoreScreen(), null); } // If not already loading else if (!isLoading) { // Start loading the resources in an additional thread thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets)); isLoading = true; thread.Start(); } }
/// <summary> /// Handle the player's input. /// </summary> /// <param name="gameTime"> /// The game Time. /// </param> /// <param name="input"> /// gamepad input state /// </param> public override void HandleInput(GameTime gameTime, InputState input) { if (IsActive) { if (input == null) { throw new ArgumentNullException("input"); } this.input = input; VirtualThumbsticks.Update(input); if (input.IsPauseGame(null)) { pauseCurrentGame(); } } if (input.TouchState.Count > 0) { foreach (TouchLocation touch in input.TouchState) { lastTouchPosition = touch.Position; } } if (input.Gestures.Count > 0) { if (isLevelEnd) { if (input.Gestures[0].GestureType == GestureType.Tap) { userTapToExit = true; } } } }
/// <summary> /// Handle thumbstick logic /// </summary> public void HandleThumbStick(Block[,] blocks, Bomberman bomberman, InputState input) { this.blocks = blocks; isSmokeButtonClicked = false; IEnumerable<Bomb> bombsToBeDeleted = bomberman.Bombs.Where(bomb => bomb.IsExploded); if (bombsToBeDeleted.Count() > 0) { foreach (Bomb bomb in bombsToBeDeleted) { screenManager.Game.Components.Remove(bomb); bomb.Stop(); } } // If there was any touch if (VirtualThumbsticks.RightThumbstickCenter.HasValue) { // Button BodyRectangle Rectangle buttonRectangle = new Rectangle((int) smokeButtonPosition.X, (int) smokeButtonPosition.Y, 60, 109); // Touch BodyRectangle Rectangle touchRectangle = new Rectangle((int) VirtualThumbsticks.RightThumbstickCenter.Value.X, (int) VirtualThumbsticks.RightThumbstickCenter.Value.Y, 1, 1); // If the touch is in the button if (buttonRectangle.Contains(touchRectangle)) { isSmokeButtonClicked = true; } } if (input.TouchState.Count > 0) { foreach (TouchLocation touch in input.TouchState) { lastTouchPosition = touch.Position; } } // Calculate the rectangle of the outer circle of the thumbstick Rectangle outerControlstick = new Rectangle( 0, (int) controlstickBoundaryPosition.Y - 35, controlstickBoundary.Width + 60, controlstickBoundary.Height + 60); //handle bomb Button if (isSmokeButtonClicked) { dropBomb(bomberman); } // Reset the thumbstick position when it is idle if (VirtualThumbsticks.LeftThumbstick == Vector2.Zero) { bomberman.SetMovement(Vector2.Zero); controlstickStartupPosition = new Vector2(55, 369); } else { // If not in motion and the touch point is not in the control bounds - there is no movement Rectangle touchRectangle = new Rectangle((int) lastTouchPosition.X, (int) lastTouchPosition.Y, 1, 1); if (!outerControlstick.Contains(touchRectangle)) { controlstickStartupPosition = new Vector2(55, 369); return; } // Move the beekeeper setMotion(bomberman); // Moves the thumbstick's inner circle float radious = controlstick.Width/2 + 35; controlstickStartupPosition = new Vector2(55, 369) + (VirtualThumbsticks.LeftThumbstick*radious); } }