public override StateChangeInformation OnUpdate(float elapsedTime) { _globalTime += elapsedTime; _explosionManager.Update(elapsedTime); _gameBackground.Update(elapsedTime); _carManager.Update(elapsedTime); _player.Update(elapsedTime); _weather.Update(elapsedTime); if (_playerIsDead) { _waitTimer += elapsedTime; if (_waitTimer >= 3.0f) { return(StateChangeInformation.StateChange(typeof(GameOverState), typeof(FlipTransition), _player.Points)); } } else if (!_playerIsDead && _player.PlayerState == PlayerState.Dead) { SoundService.StopCurrentSong(); _playerIsDead = true; _waitTimer = 0; } _carManager.spawnTime = (100 - _player.Points / 50); if (_carManager.spawnTime <= 10) { _carManager.spawnTime = 10; } _carManager.points = _player.Points + 150; return(StateChangeInformation.Empty); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } switch (gameState) { case GameStates.TitleScreen: titleScreenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (titleScreenTimer >= titleScreenDelayTime) { if ((Keyboard.GetState().IsKeyDown(Keys.Space)) || (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)) { playerManager.LivesRemaining = playerStartingLives; playerManager.PlayerScore = 0; ResetGame(); gameState = GameStates.Playing; } } break; case GameStates.Playing: starField.Update(gameTime); asteroidManager.Update(gameTime); playerManager.Update(gameTime); enemyManager.Update(gameTime); explosionManager.Update(gameTime); collisionManager.CheckCollisions(); if (playerManager.Destroyed) { playerDeathTimer = 0f; enemyManager.Active = false; playerManager.LivesRemaining--; if (playerManager.LivesRemaining < 0) { gameState = GameStates.GameOver; } else { gameState = GameStates.PlayerDead; } } break; case GameStates.PlayerDead: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { ResetGame(); gameState = GameStates.Playing; } break; case GameStates.GameOver: playerDeathTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; starField.Update(gameTime); asteroidManager.Update(gameTime); enemyManager.Update(gameTime); playerManager.PlayerShotManager.Update(gameTime); explosionManager.Update(gameTime); if (playerDeathTimer >= playerDeathDelayTime) { gameState = GameStates.TitleScreen; } break; } base.Update(gameTime); }