Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //check if player is dead
            if ((Game1.spriteManager.Hero as Player).Health <= 0)
            {
                gameState = GameStates.Game_Over;
                gameOver  = true;
            }
            if ((Game1.spriteManager.Hero as Player).totalCollected == maxNuts)
            {
                gameState = GameStates.Game_Over;
                gameOver  = true;
            }

            keyboardState = Keyboard.GetState();
            //skips over all game logic while game is paused
            if (gameState == GameStates.Paused)
            {
                menu.Update(gameTime);  //needed so the update functionality in the menu class still works while paused
                return;
            }
            else if (gameState == GameStates.Main_Menu)
            {
                mainMenu.Update(gameTime);  //needed so the mainmenu functionality still updates
                return;
            }
            else if (gameState == GameStates.Game_Over)
            {
                statsScreen.gameOver = true;
                statsScreen.Update(gameTime);  //needed so the mainmenu functionality still updates
                return;
            }
            else
            {
                //opens the game menu
                if (oldKeyboardState.IsKeyUp(Keys.Escape) && keyboardState.IsKeyDown(Keys.Escape))
                {
                    gameState = GameStates.Paused;
                }
            }
            oldKeyboardState = Keyboard.GetState();

            //check for returning nuts to home tree
            if (spriteManager.Hero.collidesWith(spriteManager.HomeTree))
            {
                (spriteManager.Hero as Player).dropOff();
            }

            base.Update(gameTime);
        }