Exemple #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            base.Update(gameTime);

            if (IsActive)
            {
                float deltaTime     = (float)gameTime.ElapsedGameTime.TotalSeconds;
                float totalGameTime = (float)gameTime.TotalGameTime.TotalSeconds;

                _gamePadVibrationController.Update(deltaTime);
                _cameraShaker.Update(deltaTime);

                switch (_gameScreen)
                {
                case GameScreen.HomeScreen:
                {
                    bool switchScreen = _homeScreen.Update(deltaTime, totalGameTime);
                    if (switchScreen)
                    {
                        _homeScreen.StopMusic();
                        _cinematicScreen.ResetScreen();

                        Fader.Instance.StartFadeOut();

                        SetGameScreen(GameScreen.CinematicScreen);
                    }
                }
                break;

                case GameScreen.CinematicScreen:
                {
                    bool switchScreen = _cinematicScreen.Update(deltaTime, totalGameTime);

                    if (switchScreen)
                    {
                        _instructionScreen.ResetScreen();

                        Fader.Instance.StartFadeOut();
                        SetGameScreen(GameScreen.InstructionsScreen);
                    }
                }
                break;

                case GameScreen.InstructionsScreen:
                {
                    bool switchScreen = _instructionScreen.Update(deltaTime, totalGameTime);

                    if (switchScreen)
                    {
                        _mainScreen.ResetScreen();
                        _mainScreen.StartMusic();

                        Fader.Instance.StartFadeOut();

                        SetGameScreen(GameScreen.MainScreen);
                    }
                }
                break;


                case GameScreen.MainScreen:
                {
                    bool switchScreens = _mainScreen.Update(deltaTime, totalGameTime);
                    if (switchScreens)
                    {
                        _mainScreen.StopMusic();
                        _gameOverScreen.ResetScreen();

                        Fader.Instance.StartFadeOut();

                        SetGameScreen(GameScreen.GameOverScreen);
                    }
                }
                break;

                case GameScreen.GameOverScreen:
                {
                    bool switchScreens = _gameOverScreen.Update(deltaTime, totalGameTime);
                    if (switchScreens)
                    {
                        _homeScreen.StartMusic();
                        _homeScreen.ResetScreen();

                        Fader.Instance.StartFadeOut();

                        SetGameScreen(GameScreen.HomeScreen);
                    }
                }
                break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                _screenFader.Update(deltaTime);
            }
            else
            {
                _gamePadVibrationController.StopVibration();
            }
        }