public override void HandleInput(InputState input)
        {
            // cancel the current screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, null, out player))
            {
                ExitScreen();
            }

            RootControl.HandleInput(input);

            base.HandleInput(input);
        }
Пример #2
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(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);
                        }
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            try
            {
                if (input == null)
                    throw new ArgumentNullException("input");
                if (input.IsPauseGame(null))
                {
                    PauseCurrentGame();
                }
                // Look up inputs for the active player profile.
                if (ControllingPlayer != null)
                {
                    var playerIndex = (int)ControllingPlayer.Value;

            #pragma warning disable 168
                    KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
                    GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];
            #pragma warning restore 168
                }

                // if the user pressed the back button, we return to the main menu
                PlayerIndex player;
                if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
                {
                    //SaveGame();
                    LoadingScreen.Load(ScreenManager, false, ControllingPlayer, new BackgroundScreen(),
                                       new MainMenuScreen());

                }
                else
                {
                    foreach (GestureSample gest in input.Gestures)
                    {
                        //Screen touch point
                        var stp = new Point((int)gest.Position.X, (int)gest.Position.Y);
                        //Map touch point
                        var mtp = new Point((int)(_camera.Position.X + gest.Position.X),
                                            (int)(_camera.Position.Y + gest.Position.Y));

                        switch (gest.GestureType)
                        {
                            case GestureType.Tap:
                                {
                                    _currentTouchPosition = (_camera.Position + gest.Position);
                                    if (
                                        !(HUD.HandleInput(stp)
                                        || PlayerManager.HandleInput(mtp, stp)
                                        || EnemyManager.HandleInput(mtp))
                                        )
                                    {
                                        if (!IsPaused)
                                            PlayerManager.Nathaniel.Destination = (_currentTouchPosition);
                                    }

                                    if (IsPaused && !GameManager.GameOver)
                                    {
                                        _pauseMenu.HandleInput(stp);
                                    }
                                    if (GameManager.GameOver)
                                        _gameOverScreen.HandleInput(stp);
                                    if (GameManager.LevelWon)
                                        _winScreen.HandleInput(stp);
                                    //Touching the screen should move the main character unless an action is being performed
                                    //on something else

                                }
                                break;

                            case GestureType.FreeDrag:
                                {
                                    BuildStructureMenu.HandleBuildMenuSelection(stp, gest);
                                }
                                break;
                            case GestureType.DragComplete:
                                {
                                    BuildStructureMenu.TryPlaceDefensiveStructure();
                                }
                                break;
                        }
                    }
                }
            }
            catch
            {
                //Empty
            }
        }