示例#1
0
        /// <summary>
        /// Updates the state of the game. This method checks the GameScreen.IsActive
        /// property, so the game will stop updating when the pause menu is active,
        /// or if you tab away to a different application.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);

            newKeyboardState = Keyboard.GetState();
            newMouseState    = Mouse.GetState();

            shoes.Update(gameTime, ref guy);
            guy.Update(gameTime, ref shoes, ref level);

            if (guy.AreGuyAndShoesCurrentlyLinked && newMouseState.LeftButton == ButtonState.Pressed &&
                !Utilities.movementLockedDueToActivePauseScreen)
            {
                TrajectoryLineHandler.Update(ref guy);
            }

            mouseRect = new Rectangle(newMouseState.X, newMouseState.Y, 16, 16);

            // Handles for if the player hits the Guy with the mouse cursor.
            handleSlappingSoundEffect();

            foreach (Air air in Air.allAirs)
            {
                air.Update(gameTime, ref shoes, ref guy);
            }

            // Hide and display the interface.
            if (!newKeyboardState.IsKeyDown(Keys.F10) && oldKeyboardState.IsKeyDown(Keys.F10))
            {
                if (displayInterface)
                {
                    displayInterface = false;
                }
                else
                {
                    displayInterface = true;
                }
            }

            MusicHandler.FadeOutMusicIfPossible(shoes.stopPlayerInputDueToLevelCompletion);

            // If the player has won the game, play the end of game sound effect.
            playEndOfGameSoundEffectIfPossible();

            // Exit to the main menu if possible.
            exitToMainMenuIfNeeded();

            // If the player presses the 'R' key, reset the player to the beginning of the level.
            restartLevelIfNecessary();

            oldKeyboardState = newKeyboardState;
            oldMouseState    = newMouseState;

            // Gradually fade in or out depending on whether we are covered by the pause screen.
            if (coveredByOtherScreen)
            {
                pauseAlpha = Math.Min(pauseAlpha + 1f / 32, 1);
            }

            else
            {
                pauseAlpha = Math.Max(pauseAlpha - 1f / 32, 0);
            }
        }