/// <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 (gameOver)
            {
                if (input.IsPauseGame(null))
                {
                    FinishCurrentGame();
                }

                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.Tap)
                    {
                        FinishCurrentGame();
                    }
                }

                return;
            }

            if (input.IsPauseGame(null))
            {
                PauseCurrentGame();
            }
            else if (isHumanTurn &&
                     (player.Catapult.CurrentState == CatapultState.Idle ||
                      player.Catapult.CurrentState == CatapultState.Aiming))
            {
                // First we try with mouse input
                player.HandleInput(input);
                if (input.MouseGesture == MouseGestureType.FreeDrag)
                {
                    isDragging = true;
                }
                else if (input.MouseGesture == MouseGestureType.DragComplete)
                {
                    isDragging = false;
                }

                // Read all available gestures
                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.FreeDrag)
                    {
                        isDragging = true;
                    }
                    else if (gestureSample.GestureType == GestureType.DragComplete)
                    {
                        isDragging = false;
                    }

                    player.HandleInput(gestureSample);
                }
            }
        }
Exemplo n.º 2
0
        /// <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 (gameOver)
            {
                if (input.IsPauseGame(null))
                {
                    FinishCurrentGame();
                }

                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.Tap)
                    {
                        FinishCurrentGame();
                    }
                }

                return;
            }

            if (input.IsPauseGame(null))
            {
                PauseCurrentGame();
            }
            else if (isCameraMoving) // Handle camera movement
            {
                // Read all available gestures
                foreach (GestureSample gestureSample in input.Gestures)
                {
                    switch (gestureSample.GestureType)
                    {
                    case GestureType.FreeDrag:
                        if (CatapultTapped(gestureSample.Position))
                        {
                            // Allow player to fire
                            isCameraMoving = false;
                            CenterOnPosition(player.Catapult.Position +
                                             catapultCenterOffset);
                        }
                        else
                        {
                            isDragging = true;

                            // Move screen according to delta
                            Vector2 newOffset = DrawOffset;
                            newOffset += gestureSample.Delta;
                            DrawOffset = ClampDrawOffset(newOffset);
                        }
                        break;

                    case GestureType.DragComplete:
                        // turn off dragging state
                        ResetDragState();
                        break;

                    case GestureType.Tap:
                        if (isCameraMoving)
                        {
                            isFlying = false;
                        }
                        break;

                    case GestureType.Flick:
                        // Ignore flicks which appear as part of a pinch ending
                        if (lastGestureType != GestureType.PinchComplete)
                        {
                            FlyToPositionNoScale(
                                ScreenCenter - gestureSample.Delta);
                        }
                        break;

                    case GestureType.Pinch:

                        // Store last drag location
                        if (null == prevSample)
                        {
                            prevSample = gestureSample;
                        }
                        else
                        {
                            prevSample = currentSample;
                        }

                        // save the current gesture sample
                        currentSample = gestureSample;

                        float currentLength = (currentSample.Value.Position -
                                               currentSample.Value.Position2).Length();
                        float previousLength = (prevSample.Value.Position -
                                                prevSample.Value.Position2).Length();

                        float scaleChange = (currentLength - previousLength) * 0.05f;

                        Vector2 previousCenter = ScreenCenter;
                        float   previousScale  = DrawScale;

                        DrawScale += scaleChange;

                        DrawScale = MathHelper.Clamp(DrawScale, MinScale, MaxScale);

                        CenterOnPositionNoScale(previousCenter * DrawScale / previousScale);
                        break;

                    case GestureType.PinchComplete:
                        ResetPinchState();
                        break;

                    default:
                        break;
                    }

                    lastGestureType = gestureSample.GestureType;
                }
            }
            else if (isHumanTurn &&
                     (player.Catapult.CurrentState == CatapultState.Idle ||
                      player.Catapult.CurrentState == CatapultState.Aiming))
            {
                // Read all available gestures
                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.FreeDrag)
                    {
                        isDragging = true;
                    }
                    else if (gestureSample.GestureType == GestureType.DragComplete)
                    {
                        isDragging = false;
                    }

                    player.HandleInput(gestureSample);
                }
            }
        }
Exemplo n.º 3
0
        /// <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 (gameOver)
            {
                if (input.IsPauseGame(null))
                {
                    FinishCurrentGame();
                }

                if (input.MouseGesture.HasFlag(MouseGestureType.LeftClick))
                {
                    FinishCurrentGame();
                }

                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.Tap)
                    {
                        FinishCurrentGame();
                    }
                }

                return;
            }

            if (NetworkSession != null)
            {
                if ((isFirstPlayerTurn && !NetworkSession.IsHost) ||
                    (!isFirstPlayerTurn && NetworkSession.IsHost))
                {
                    return;
                }
            }

            if (input.IsPauseGame(null))
            {
                PauseCurrentGame();
            }
            else if (isFirstPlayerTurn &&
                     (playerOne.Catapult.CurrentState == CatapultState.Idle ||
                      playerOne.Catapult.CurrentState == CatapultState.Aiming))
            {
                // First we try with mouse input
                playerOne.HandleInput(input);
                isDragging = playerOne.isDragging;

                // Read all available gestures
                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.FreeDrag)
                    {
                        isDragging = true;
                    }
                    else if (gestureSample.GestureType == GestureType.DragComplete)
                    {
                        isDragging = false;
                    }

                    playerOne.HandleInput(gestureSample);
                }
            }
            else if (!isFirstPlayerTurn &&
                     (playerTwo.Catapult.CurrentState == CatapultState.Idle ||
                      playerTwo.Catapult.CurrentState == CatapultState.Aiming))
            {
                // First we try with mouse input
                playerTwo.HandleInput(input);
                isDragging = playerTwo.isDragging;

                // Read all available gestures
                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.FreeDrag)
                    {
                        isDragging = true;
                    }
                    else if (gestureSample.GestureType == GestureType.DragComplete)
                    {
                        isDragging = false;
                    }

                    playerTwo.HandleInput(gestureSample);
                }
            }
        }