示例#1
0
        /// <summary>
        /// Handle the player's input.
        /// </summary>
        /// <param name="input"></param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (IsActive)
            {
                if (input == null)
                {
                    throw new ArgumentNullException("input");
                }

                VirtualThumbsticks.Update(input);
            }

            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 Bounds
                Rectangle buttonRectangle = new Rectangle((int)smokeButtonPosition.X, (int)smokeButtonPosition.Y,
                                                          smokeButton.Width / 2, smokeButton.Height);

                // Touch Bounds
                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) && !beeKeeper.IsCollectingHoney && !beeKeeper.IsStung)
                {
                    isSmokebuttonClicked = true;
                }
            }

            if (input.IsKeyDown(Keys.Space, ControllingPlayer, out player) && !beeKeeper.IsCollectingHoney &&
                !beeKeeper.IsStung)
            {
                isSmokebuttonClicked = true;
            }

            if (input.Gestures.Count > 0)
            {
                if (isLevelEnd)
                {
                    if (input.Gestures[0].GestureType == GestureType.Tap)
                    {
                        ScreenManager.RemoveScreen(this);
                        ScreenManager.AddScreen(new GameplayScreen(DifficultyMode.Easy), null);
                    }
                }
            }
        }
        /// <summary>
        /// Handle the player's input.
        /// </summary>
        /// <param name="input"></param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (IsActive)
            {
                if (input == null)
                {
                    throw new ArgumentNullException("input");
                }

                if (input.IsPauseGame(null))
                {
                    PauseCurrentGame();
                }
            }

            if (input.TouchState.Count > 0)
            {
                foreach (TouchLocation touch in input.TouchState)
                {
                    lastTouchPosition = touch.Position;
                }
            }

            isSmokebuttonClicked = false;

            PlayerIndex player;

            VirtualThumbsticks.Update(input);

            if (input.Gestures.Count > 0)
            {
                GestureSample topGesture = input.Gestures[0];

                if (topGesture.GestureType == GestureType.Tap &&
                    deviceUpperRightCorner.Contains(new Point((int)topGesture.Position.X, (int)topGesture.Position.Y)))
                {
                    showDebugInfo = !showDebugInfo;
                }
            }

            if (isLevelEnd)
            {
                if (input.Gestures.Count > 0)
                {
                    if (input.Gestures[0].GestureType == GestureType.Tap)
                    {
                        userInputToExit = true;
                    }
                }
                else if (input.IsNewButtonPress(Buttons.A, ControllingPlayer,
                                                out player))
                {
                    userInputToExit = true;
                }

                if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                    input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
                {
                    userInputToExit = true;
                }
            }

            if (!IsStarted)
            {
                return;
            }

            // If there was any touch
            if (VirtualThumbsticks.RightThumbstickCenter.HasValue)
            {
                // Button Bounds
                Rectangle buttonRectangle = new Rectangle((int)smokeButtonPosition.X, (int)smokeButtonPosition.Y,
                                                          smokeButton.Width / 2, smokeButton.Height);

                // Touch Bounds
                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) && !beeKeeper.IsCollectingHoney && !beeKeeper.IsStung)
                {
                    isSmokebuttonClicked = true;
                }
            }

            if (input.IsNewButtonPress(Buttons.Y, ControllingPlayer, out player))
            {
                showDebugInfo = !showDebugInfo;
            }
            else if (input.IsButtonDown(Buttons.A, ControllingPlayer, out player) && !beeKeeper.IsCollectingHoney &&
                     !beeKeeper.IsStung)
            {
                isSmokebuttonClicked = true;
            }

            // Handle keyboard
            if (input.IsNewKeyPress(Keys.Y, ControllingPlayer, out player))
            {
                showDebugInfo = !showDebugInfo;
            }
            if (input.IsKeyDown(Keys.Space, ControllingPlayer, out player) && !beeKeeper.IsCollectingHoney &&
                !beeKeeper.IsStung)
            {
                isSmokebuttonClicked = true;
            }

            movementVector = SetMotion(input);
            beeKeeper.SetDirection(movementVector);
        }