示例#1
0
        /// <summary>
        /// Perform the game's update logic.
        /// </summary>
        /// <param name="gameTime">Game time information.</param>
        /// <param name="otherScreenHasFocus">Whether or not another screen currently has the focus.</param>
        /// <param name="coveredByOtherScreen">Whether or not this screen is covered by another.</param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            gameElapsed -= gameTime.ElapsedGameTime;

            if (vat.CurrentVatCapacity >= vat.MaxVatCapacity || gameElapsed <= TimeSpan.Zero)
            {
                isLevelEnd = true;
            }
            if (isLevelEnd)
            {
                return;
            }

            // Update the time remaining displayed by the vat
            vat.DrawTimeLeft(gameElapsed);


            // If active and running handle all game component
            if (!IsActive)
            {
                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
                return;
            }

            HandleThumbStick();

            HandleSmoke();

            beeKeeper.SetDirection(VirtualThumbsticks.LeftThumbstick);

            HandleCollision(gameTime);

            HandleVatHoneyArrow();

            beeKeeper.DrawOrder = 1;
            int beeKeeperY = (int)(beeKeeper.Position.Y + beeKeeper.Bounds.Height - 2);

            // We want to determine the draw order of the beekeeper,
            // if the beekeeper is under half the height of the beehive
            // it should be drawn over the beehive.
            foreach (Beehive beehive in beehives)
            {
                if (beeKeeperY > beehive.Bounds.Y)
                {
                    if (beehive.Bounds.Y + beehive.Bounds.Height / 2 < beeKeeperY)
                    {
                        beeKeeper.DrawOrder = Math.Max(beeKeeper.DrawOrder, beehive.Bounds.Y + 1);
                    }
                }
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        /// <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);
        }
        /// <summary>
        /// Perform the game's update logic.
        /// </summary>
        /// <param name="gameTime">Game time information.</param>
        /// <param name="otherScreenHasFocus">Whether or not another screen currently has the focus.</param>
        /// <param name="coveredByOtherScreen">Whether or not this screen is covered by another.</param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // When the game starts the first thing the user sees is the count down before the game actually begins
            if (isAtStartupCountDown)
            {
                startScreenTime -= gameTime.ElapsedGameTime;
            }

            // Check for and handle a game over
            if (CheckIfCurrentGameFinished())
            {
                base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

                return;
            }

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

            // Show all diagnostic counters
            debugSystem.FpsCounter.Visible = showDebugInfo;
            debugSystem.TimeRuler.Visible  = showDebugInfo;
            debugSystem.TimeRuler.ShowLog  = showDebugInfo;

            gameElapsed -= gameTime.ElapsedGameTime;

            HandleThumbStick();

            HandleSmoke();

            beeKeeper.SetDirection(VirtualThumbsticks.LeftThumbstick);

            HandleCollision(gameTime);

            HandleVatHoneyArrow();

            beeKeeper.DrawOrder = 1;
            int beeKeeperY = (int)(beeKeeper.Position.Y + beeKeeper.Bounds.Height - 2);

            // We want to determine the draw order of the beekeeper,
            // if the beekeeper is under half the height of the beehive
            // it should be drawn over the beehive.
            foreach (Beehive beehive in beehives)
            {
                if (beeKeeperY > beehive.Bounds.Y)
                {
                    if (beehive.Bounds.Y + beehive.Bounds.Height / 2 < beeKeeperY)
                    {
                        beeKeeper.DrawOrder = Math.Max(beeKeeper.DrawOrder, beehive.Bounds.Y + 1);
                    }
                }
            }

            if (gameElapsed.Minutes == 0 && gameElapsed.Seconds == 10)
            {
                AudioManager.PlaySound("10SecondCountDown");
            }
            if (gameElapsed.Minutes == 0 && gameElapsed.Seconds == 30)
            {
                AudioManager.PlaySound("30SecondWarning");
            }

            // Update the time remaining displayed on the vat
            vat.DrawTimeLeft(gameElapsed);

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }