示例#1
0
        /// <summary>
        /// Exit the screen after a tap gesture
        /// </summary>
        /// <param name="input"></param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (!isLoading)
            {
                PlayerIndex player;

                // Handle touch input
                if (input.Gestures.Count > 0)
                {
                    if (input.Gestures[0].GestureType == GestureType.Tap)
                    {
                        LoadResources();
                    }
                }
                else if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player) ||
                         input.IsNewKeyPress(Keys.Escape, ControllingPlayer, out player))
                {
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(new BackgroundScreen("titleScreen"), null);
                    ScreenManager.AddScreen(new MainMenuScreen(), PlayerIndex.One);
                }
                else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                         input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player) ||
                         input.IsNewButtonPress(Buttons.A, ControllingPlayer, out player))
                {
                    LoadResources();
                }
            }

            base.HandleInput(gameTime, input);
        }
示例#2
0
        /// <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 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");
            }

            PlayerIndex player;

            // 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();
                }
            }
            // Handle gamepad
            else if (input.IsNewButtonPress(Buttons.A, ControllingPlayer, out player))
            {
                StartNewLevelOrExit(input);
            }
            // Handle keyboard
            else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                     input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
            {
                StartNewLevelOrExit(input);
            }

            base.HandleInput(gameTime, input);
        }
示例#4
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex player;

            if (input.IsNewButtonPress(Buttons.Start, ControllingPlayer, out player))
            {
                ReturnGameMenuEntrySelected(this, new EventArgs());
            }

            base.HandleInput(gameTime, input);
        }
示例#5
0
        /// <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);
            }

            // Take care of Keyboard input
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }
            else if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }
            else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
            {
                OnSelectEntry(selectedEntry, 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="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);
        }