protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); //Debug input #if DEBUG if (Keyboard.GetState().IsKeyDown(Keys.OemTilde)) { GameState = GameState.Splash; SplashType = SplashScreenType.GameOver; loadSplashScreen(new Credits()); } #endif if (Keyboard.GetState().IsKeyDown(Keys.Y) && oldKS.IsKeyUp(Keys.Y)) { //CurrentLevel++; if (CurrentLevel < Levels.Count) { LevelManager.LevelDone = true; } } float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; // Update according to current game state switch (GameState) { case GameState.Initializing: if (!LevelManager.Loading) GameState = GameState.Gameplay; break; case GameState.Splash: if (SplashType == SplashScreenType.GameStart ) { if (Splash.Done && Keyboard.GetState().IsKeyDown(Keys.Enter)) { //the game is starting, load the first cutscene and update to the first line of dialog SplashType = SplashScreenType.Beginning; loadSplashScreen(new Beginning()); } } else if (SplashType == SplashScreenType.GameOver) //Should be Gameover or credits { if (Splash.Done && Keyboard.GetState().IsKeyDown(Keys.Enter)) { //Game over reload first screen. SplashType = SplashScreenType.GameStart; loadSplashScreen(new GameStart()); } } else if (Splash.Done || Keyboard.GetState().IsKeyDown(Keys.S) && oldKS.IsKeyUp(Keys.S)) { //Load next level CurrentLevel = Splash.NextLevel; Reset(); } //Otherwise update. Splash.Update(elapsedTime); break; case GameState.Gameplay: LevelManager.Update(elapsedTime); if (!LevelManager.Ending) { GameObjectManager.Update(elapsedTime); ProcessCollisions(); } if (LevelManager.LevelDone) { switch (CurrentLevel) { case 1: SplashType = SplashScreenType.EndLevelOne; Splash = new EndLevelOne(); break; case 2: SplashType = SplashScreenType.EndLevelTwo; Splash = new EndLevelTwo(); break; case 3: SplashType = SplashScreenType.EndLevelThree; Splash = new EndLevelThree(); break; case 4: SplashType = SplashScreenType.EndLevelFour; Splash = new EndLevelFour(); break; case 5: SplashType = SplashScreenType.EndLevelFive; Splash = new EndLevelFive(); break; case 6: SplashType = SplashScreenType.EndLevelSix; Splash = new EndLevelSix(); break; case 7: SplashType = SplashScreenType.EndLevelSeven; Splash = new EndLevelSix(); break; case 8: SplashType = SplashScreenType.GameOver; Splash = new Credits(); break; } GameState = GameState.Splash; Splash.Update(elapsedTime); } else if (LevelManager.ResetLevel) { //Should be handle by player death method. Reset(); LevelManager.ResetLevel = false; Player.Score = 0; Player.Lives = 5; Player.Health = Player.MaxHealth; Player.Dead = false; } break; case GameState.Scoring: //Not used GuiManager.Update(elapsedTime); if (GuiManager.tallyState == GuiManager.TallyingState.PressSpaceToContinue && Keyboard.GetState().IsKeyDown(Keys.Space)) { GameState = GameState.Splash; Music = Splash.Music; if (Music != null) MediaPlayer.Play(Music); } break; } oldKS = Keyboard.GetState(); base.Update(gameTime); }