public void SetCurrentState(TouchInputState state)
        {
            switch (_CurrentState)
            {
            case TouchInputState.TAPPING:
                break;

            case TouchInputState.DRAGGING:
                OnDragStop?.Invoke();
                break;

            case TouchInputState.PINCHING:
                OnPinchStop?.Invoke();
                break;
            }

            switch (state)
            {
            case TouchInputState.TAPPING:
                break;

            case TouchInputState.DRAGGING:
                OnDragStart?.Invoke();
                break;

            case TouchInputState.PINCHING:
                OnPinchStart?.Invoke();
                break;
            }

            _CurrentState = state;
        }
Beispiel #2
0
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The input to handle.</param>
        public override void HandleInput(InputState input)
        {
            if (IsActive)
            {
                if (input == null)
                {
                    throw new ArgumentNullException("input");
                }

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

                if (input.TouchState.Count > 0)
                {
                    // We are about to handle touch input
                    switch (inputState)
                    {
                    case TouchInputState.Idle:
                        // We have yet to receive input, start grace period
                        inputTimeMeasure = TimeSpan.Zero;
                        inputState       = TouchInputState.GracePeriod;
                        lastPressInput   = new List <TouchLocation>();
                        foreach (var touch in input.TouchState)
                        {
                            if (touch.State == TouchLocationState.Pressed)
                            {
                                lastPressInput.Add(touch);
                            }
                        }
                        break;

                    case TouchInputState.GracePeriod:
                        // Do nothing during the grace period other than remembering
                        // additional presses
                        foreach (var touch in input.TouchState)
                        {
                            if (touch.State == TouchLocationState.Pressed)
                            {
                                lastPressInput.Add(touch);
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
 public void CheckCurrentState()
 {
     if (Input.touchCount == 2)
     {
         touchState = TouchInputState.Zoom;
     }
     else if (Input.touchCount == 1)
     {
         if (Input.GetTouch(0).phase == TouchPhase.Began)
         {
             touchState = TouchInputState.Action;
             Debug.Log("Touch began");
         }
     }
 }
 // Use this for initialization
 void Start()
 {
     inputState = TouchInputState.UNITMOVE;
 }
 public void UnitMovePhase()
 {
     inputState = TouchInputState.UNITMOVE;
 }
 public void UnitSelectPhase()
 {
     inputState = TouchInputState.UNITSELECT;
 }
Beispiel #7
0
        /// <summary>
        /// Update all the game component
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // Do not advance to the highscore screen if sounds are playing
            if (moveToHighScore && !AudioManager.AreSoundsPlaying())
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                foreach (GameScreen screen in ScreenManager.GetScreens())
                {
                    screen.ExitScreen();
                }

                ScreenManager.AddScreen(new BackgroundScreen(true), null);
                ScreenManager.AddScreen(new HighScoreScreen(), null);
            }

            // Do not perform advance update logic if the game is inactive or we are
            // moving to the highscore screen
            if (!IsActive || moveToHighScore)
            {
                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                return;
            }

            if ((inputState == TouchInputState.GracePeriod) && (isActive))
            {
                inputTimeMeasure += gameTime.ElapsedGameTime;

                // if the input grace period is over, handle the touch input
                if (inputTimeMeasure >= inputGracePeriod)
                {
                    currentLevel.RegisterTouch(lastPressInput);
                    inputState = TouchInputState.Idle;
                }
            }

            // If the user passed the level, advance to the next or finish the game if
            // the current level was last
            if (currentLevel.CurrentState == LevelState.FinishedOk && isActive)
            {
                AudioManager.PlaySound("success");

                if (currentLevelNumber < maxLevelNumber)
                {
                    currentLevelNumber++;
                    isLevelChange = true;
                }
                else
                {
                    FinishCurrentGame();
                }
            }
            // If the user failed to pass the level, revert to level one, allowing the
            // user to register a highscore if he reached a high enough level
            else if (currentLevel.CurrentState == LevelState.FinishedFail)
            {
                isActive = false;

                if (HighScoreScreen.IsInHighscores(currentLevelNumber))
                {
                    // The player has a highscore - show the device's keyboard
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                                                 Constants.HighscorePopupTitle, Constants.HighscorePopupText,
                                                 Constants.HighscorePopupDefault, ShowHighscorePromptEnded,
                                                 false);
                }
                else
                {
                    AudioManager.PlaySound("fail");
                    isActive           = true;
                    currentLevelNumber = 1;
                    isLevelChange      = true;
                }
            }

            if (isLevelChange)
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                currentLevel = new Level(ScreenManager.Game,
                                         ScreenManager.SpriteBatch,
                                         currentLevelNumber, buttonsTexture);
                currentLevel.IsActive = true;

                ScreenManager.Game.Components.Add(currentLevel);

                isLevelChange = false;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            //TODO #8
            //if ((moveToHighScore) && (!AudioManager.AreSoundsPlaying()))
            //{
            //    ScreenManager.Game.Components.Remove(currentLevel);

            //    foreach (GameScreen screen in ScreenManager.GetScreens())
            //        screen.ExitScreen();

            //    ScreenManager.AddScreen(new BackgroundScreen(true), null);
            //    ScreenManager.AddScreen(new HighScoreScreen(), null);
            //}

            if (!IsActive || moveToHighScore)
            {
                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                return;
            }

            bool isLevelChange = false;

            if ((inputState == TouchInputState.GracePeriod) && (isActive))
            {
                inputTimeMeasure += gameTime.ElapsedGameTime;

                // if the input grace period is over, handle the touch input
                if (inputTimeMeasure >= inputGracePeriod)
                {
                    currentLevel.RegisterTouch(lastPressInput);
                    inputState = TouchInputState.Idle;
                }
            }

            if (currentLevel.CurrentState == LevelState.FinishedOk && isActive)
            {
                //TODO #9


                if (currentLevelNumber < maxLevelNumber)
                {
                    currentLevelNumber++;
                    isLevelChange = true;
                }
                else
                {
                    //TODO #10 - REPLACE
                    ScreenManager.Game.Exit();
                    //FinishCurrentGame();
                }
            }
            else if (currentLevel.CurrentState == LevelState.FinishedFail)
            {
                //TODO #11


                currentLevelNumber = 1;
                isLevelChange      = true;
            }

            if (isLevelChange)
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                currentLevel = new Level(ScreenManager.Game,
                                         ScreenManager.SpriteBatch,
                                         currentLevelNumber, buttonsTexture);
                currentLevel.IsActive = true;

                ScreenManager.Game.Components.Add(currentLevel);
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
 void Start()
 {
     touchState = TouchInputState.Idle;
 }
        /// <summary>
        /// Update all the game component
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // Do not advance to the highscore screen if sounds are playing
            if (moveToHighScore && !AudioManager.AreSoundsPlaying())
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                foreach (GameScreen screen in ScreenManager.GetScreens())
                    screen.ExitScreen();

                ScreenManager.AddScreen(new BackgroundScreen(true), null);
                ScreenManager.AddScreen(new HighScoreScreen(), null);
            }

            // Do not perform advance update logic if the game is inactive or we are
            // moving to the highscore screen
            if (!IsActive || moveToHighScore)
            {
                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                return;
            }

            if ((inputState == TouchInputState.GracePeriod) && (isActive))
            {
                inputTimeMeasure += gameTime.ElapsedGameTime;

                // if the input grace period is over, handle the touch input
                if (inputTimeMeasure >= inputGracePeriod)
                {
                    currentLevel.RegisterTouch(lastPressInput);
                    inputState = TouchInputState.Idle;
                }
            }

            // If the user passed the level, advance to the next or finish the game if
            // the current level was last
            if (currentLevel.CurrentState == LevelState.FinishedOk && isActive)
            {
                AudioManager.PlaySound("success");

                if (currentLevelNumber < maxLevelNumber)
                {
                    currentLevelNumber++;
                    isLevelChange = true;
                }
                else
                {
                    FinishCurrentGame();
                }
            }
            // If the user failed to pass the level, revert to level one, allowing the
            // user to register a highscore if he reached a high enough level
            else if (currentLevel.CurrentState == LevelState.FinishedFail)
            {
                isActive = false;

                if (HighScoreScreen.IsInHighscores(currentLevelNumber))
                {
                    // The player has a highscore - show the device's keyboard
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                        Constants.HighscorePopupTitle, Constants.HighscorePopupText,
                        Constants.HighscorePopupDefault, ShowHighscorePromptEnded,
                        false);
                }
                else
                {
                    AudioManager.PlaySound("fail");
                    isActive = true;
                    currentLevelNumber = 1;
                    isLevelChange = true;
                }
            }

            if (isLevelChange)
            {
                ScreenManager.Game.Components.Remove(currentLevel);

                currentLevel = new Level(ScreenManager.Game,
                                            ScreenManager.SpriteBatch,
                                            currentLevelNumber, buttonsTexture);
                currentLevel.IsActive = true;

                ScreenManager.Game.Components.Add(currentLevel);

                isLevelChange = false;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The input to handle.</param>
        public override void HandleInput(InputState input)
        {
            if (IsActive)
            {
                if (input == null)
                    throw new ArgumentNullException("input");

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

                if (input.TouchState.Count > 0)
                {
                    // We are about to handle touch input
                    switch (inputState)
                    {
                        case TouchInputState.Idle:
                            // We have yet to receive input, start grace period
                            inputTimeMeasure = TimeSpan.Zero;
                            inputState = TouchInputState.GracePeriod;
                            lastPressInput = new List<TouchLocation>();
                            foreach (var touch in input.TouchState)
                            {
                                if (touch.State == TouchLocationState.Pressed)
                                {
                                    lastPressInput.Add(touch);
                                }
                            }
                            break;
                        case TouchInputState.GracePeriod:
                            // Do nothing during the grace period other than remembering
                            // additional presses
                            foreach (var touch in input.TouchState)
                            {
                                if (touch.State == TouchLocationState.Pressed)
                                {
                                    lastPressInput.Add(touch);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }