/// <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.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))
                {
                    LoadResources();
                }
            }

            base.HandleInput(gameTime, input);
        }
        /// <summary>
        /// Moves the beekeeper.
        /// </summary>
        /// <returns>Returns a vector indicating the beekeeper's movement direction.
        /// </returns>
        private Vector2 SetMotion(InputState input)
        {
            // Calculate the beekeeper location, if allow moving
            Rectangle safeArea = SafeArea;

            PlayerIndex playerIndex;

            Vector2 leftThumbstick = VirtualThumbsticks.LeftThumbstick;

            // Move on to keyboard input if we still have nothing
            if (leftThumbstick == Vector2.Zero)
            {
                float vecX = 0;
                float vecY = 0;

                if (input.IsKeyDown(Keys.Left, ControllingPlayer, out playerIndex))
                {
                    vecX--;
                }
                if (input.IsKeyDown(Keys.Right, ControllingPlayer, out playerIndex))
                {
                    vecX++;
                }
                if (input.IsKeyDown(Keys.Up, ControllingPlayer, out playerIndex))
                {
                    vecY--;
                }
                if (input.IsKeyDown(Keys.Down, ControllingPlayer, out playerIndex))
                {
                    vecY++;
                }

                leftThumbstick = new Vector2(vecX, vecY);
            }

            Vector2 movementVector = leftThumbstick * 12f * ScreenManager.SpriteBatch.ScaleVector;

            Rectangle futureBounds = beeKeeper.Bounds;
            futureBounds.X += (int)movementVector.X;
            futureBounds.Y += (int)movementVector.Y;

            if (futureBounds.Left <= safeArea.Left || futureBounds.Right >= safeArea.Right)
            {
                movementVector.X = 0;
            }
            if (futureBounds.Top <= safeArea.Top || futureBounds.Bottom >= safeArea.Bottom)
            {
                movementVector.Y = 0;
            }

            if (movementVector == Vector2.Zero)
            {
                IsInMotion = false;
                beeKeeper.SetMovement(Vector2.Zero);
            }
            else
            {
                Vector2 beekeeperCalculatedPosition =
                    new Vector2(beeKeeper.CentralCollisionArea.X, beeKeeper.CentralCollisionArea.Y) + movementVector;

                if (!CheckBeehiveCollision(beekeeperCalculatedPosition))
                {
                    beeKeeper.SetMovement(movementVector);
                    IsInMotion = true;
                }
            }

            return movementVector;
        }
        /// <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;
                    }
                }

                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;
                }
            }

            // 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);
        }
Esempio n. 4
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>
        /// Starts new level or exit to High Score
        /// </summary>
        /// <param name="input"></param>
        private void StartNewLevelOrExit(InputState input)
        {
            // If there is no next level - go to high score screen
            if (!difficultyMode.HasValue)
            {
                // If is in high score, gets is name
                if (GameplayScreen.FinalScore != 0 && HighScoreScreen.IsInHighscores(GameplayScreen.FinalScore))
                {
                    Guide.BeginShowKeyboardInput(PlayerIndex.One,
                        "Player Name", "What is your name (max 15 characters)?", "Player",
                        AfterPlayerEnterName, null);
                }
                else
                {
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(new BackgroundScreen("highScoreScreen"), null);
                    ScreenManager.AddScreen(new HighScoreScreen(), null);
                }
            }
            // If not already loading
            else if (!isLoading)
            {
#if MONOMAC			
		// Start loading the resources on main thread
		// If not then all sorts of errors happen for 
		// AutoReleasPools and OpenGL does not handle 
		// multiple thread to well when using Thread
		MonoMac.AppKit.NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate {  
			gameplayScreen.LoadAssets ();
			isLoading = false;
			assetsLoaded = true;
		});
#else				
                // Start loading the resources in an additional thread
                thread = new Thread(new ThreadStart(gameplayScreen.LoadAssets));

                isLoading = true;
                thread.Start();
#endif				
            }
        }
        /// <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 keyboard
            else if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
                input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player))
            {
                StartNewLevelOrExit(input);
            }

            base.HandleInput(gameTime, input);
        }
        /// <summary>
        /// Updates the virtual thumbsticks based on current touch state. This must be called every frame.
        /// </summary>
        public static void Update(InputState input)
        {
           
            TouchLocation? leftTouch = null;
            TouchLocation? rightTouch = null;
            TouchCollection touches = input.TouchState;

            // Examine all the touches to convert them to virtual dpad positions. Note that the 'touches'
            // collection is the set of all touches at this instant, not a sequence of events. The only
            // sequential information we have access to is the previous location for of each touch.
            foreach (TouchLocation touch in touches)
            {
                if (touch.Id == leftId)
                {
                    // This is a motion of a left-stick touch that we're already tracking
                    leftTouch = touch;
                    continue;
                }

                if (touch.Id == rightId)
                {
                    // This is a motion of a right-stick touch that we're already tracking
                    rightTouch = touch;
                    continue;
                }

                // We didn't continue an existing thumbstick gesture; see if we can start a new one.
                //
                // We'll use the previous touch position if possible, to get as close as possible to where
                // the gesture actually began.
                TouchLocation earliestTouch;
                if (!touch.TryGetPreviousLocation(out earliestTouch))
                {
                    earliestTouch = touch;
                }

                if (leftId == -1)
                {
                    // if we are not currently tracking a left thumbstick and this touch is on the left
                    // half of the screen, start tracking this touch as our left stick
                    if (earliestTouch.Position.X < TouchPanel.DisplayWidth / 2)
                    {
                        leftTouch = earliestTouch;
                        continue;
                    }
                }

                if (rightId == -1)
                {
                    // if we are not currently tracking a right thumbstick and this touch is on the right
                    // half of the screen, start tracking this touch as our right stick
                    if (earliestTouch.Position.X >= TouchPanel.DisplayWidth / 2)
                    {
                        rightTouch = earliestTouch;
                        continue;
                    }
                }
            }

            // if we have a left touch
            if (leftTouch.HasValue)
            {
                // if we have no center, this position is our center
                if (!LeftThumbstickCenter.HasValue)
                {
                    LeftThumbstickCenter = leftTouch.Value.Position;
                }

                // save the position of the touch
                leftPosition = leftTouch.Value.Position;

                // save the ID of the touch
                leftId = leftTouch.Value.Id;
            }
            else
            {
                // otherwise reset our values to not track any touches
                // for the left thumbstick
                LeftThumbstickCenter = null;
                leftId = -1;
            }

            // if we have a right touch
            if (rightTouch.HasValue)
            {
                // if we have no center, this position is our center
                if (!RightThumbstickCenter.HasValue)
                {
                    RightThumbstickCenter = rightTouch.Value.Position;
                }

                // save the position of the touch
                rightPosition = rightTouch.Value.Position;

                // save the ID of the touch
                rightId = rightTouch.Value.Id;
            }
            else
            {
                // otherwise reset our values to not track any touches
                // for the right thumbstick
                RightThumbstickCenter = null;
                rightId = -1;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Handles user input.
        /// </summary>
        /// <param name="gameTime">Game time information.</param>
        /// <param name="input">Input information.</param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (isExiting)
            {
                return;
            }

            base.HandleInput(gameTime, input);
        }
Esempio n. 9
0
        /// <summary>
        /// Handles user input as a part of screen logic update.
        /// </summary>
        /// <param name="gameTime">Game time information.</param>
        /// <param name="input">Input information.</param>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

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

            // 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)
                {
                    Exit();

                    input.Gestures.Clear();
                }
            }
            // Handle gamepad input
            PlayerIndex player;
            // Handle keyboard input
            if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out player) ||
			    input.IsNewKeyPress(Keys.Space, ControllingPlayer, out player) ||
			    input.IsNewMouseClick(InputState.MouseButton.Left, ControllingPlayer, out player))
            {
                Exit();
            }
        }