Update() private method

private Update ( ) : void
return void
Esempio n. 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)
        {
            // Update input manager.
            inputManager.Update(gameTime);

            // Exit game when exit bool is true
            if (ExitGame)
            {
                Exit();
            }
            // Makes F toggle full-screen mode.
            if (Keyboard.GetState().IsKeyDown(Keys.F))
            {
                graphics.IsFullScreen = !graphics.IsFullScreen;
                graphics.ApplyChanges();
            }


            // Create a switch for where code specific to a gamestate can be placed.
            switch (gameState)
            {
            case GameState.TitleScreen:

                // Update the main menu class.
                mainMenu.Update(gameTime);
                // Update the rain.
                rain.Update(gameTime);

                // Pause the ambient firing sounds.
                ambientFiringSoundInstance.Pause();
                // Play the other background sounds.
                rainSoundInstance.Play();
                musicInstance.Play();
                break;

            case GameState.Tutorial:
                // Update the tutorial menu class.
                tutorial.Update(gameTime);
                // Update the rain.
                rain.Update(gameTime);
                break;

            case GameState.Credits:
                // Update the credits menu class.
                credits.Update(gameTime);
                // Update the rain.
                rain.Update(gameTime);
                break;

            // PrePlaying is used to reset everything before moving to gamestate playing.
            case GameState.PrePlaying:

                gameState = GameState.Playing;
                // Reset player.
                playerSprite.Destroyed = false;
                playerSprite.Position  = playerSprite.StartingPosition;
                playerSprite.PlayerShotManager.Shots.Clear();
                // Reset score.
                scoreManager.ResetScore();
                // Reset/remove enemies and their shots.
                enemyManager.Reset();
                break;

            case GameState.Playing:
                // Player movment. Links playerSprite to HandleSpriteMovement of PlayerManager so player can move.
                playerSprite.HandleSpriteMovement(gameTime);

                // Update the rain.
                rain.Update(gameTime);

                // Update playerSprite.
                playerSprite.Update(gameTime);

                // Update enemyManager.
                enemyManager.Update(gameTime);

                // Update player and enemy explosionManager.
                enemyExplosionManager.Update(gameTime);
                playerExplosionManager.Update(gameTime);

                // Update collisionManager.
                collisionsManager.CheckCollisions();

                // Update scoreManager
                scoreManager.Update(gameTime);

                // Pause the game if escape is pressed
                if (InputManager.KBState.IsKeyDown(Keys.Escape) && InputManager.PreviousKBState.IsKeyUp(Keys.Escape))
                {
                    gameState = GameState.Paused;
                }

                // Move to Game Over if player dies.
                if (playerSprite.Destroyed)
                {
                    gameState = GameState.GameOver;
                }

                // Play the background sounds.
                ambientFiringSoundInstance.Play();
                rainSoundInstance.Play();
                musicInstance.Play();
                break;

            case GameState.Paused:
                // Update paused menu.
                paused.Update(gameTime);
                // Pause the ambient firing sounds.
                ambientFiringSoundInstance.Pause();
                rainSoundInstance.Pause();
                musicInstance.Pause();
                break;

            case GameState.GameOver:
                // Update the rain.
                rain.Update(gameTime);
                // Update explosionManager.
                enemyExplosionManager.Update(gameTime);
                playerExplosionManager.Update(gameTime);

                gameOver.Update(gameTime);
                break;
            }
            base.Update(gameTime);
        }