/// <summary> /// This function updates the screen state. /// </summary> /// <param name="gameTime">current game time</param> /// <param name="currentKey">current key press</param> public void Update(GameTime gameTime, KeyboardState currentKey) { this.currentKey = currentKey; //initialise current key press switch (screenState) { case ScreenState.Title: title.Update(currentKey); if (title.exit) { title = null; setScreen("MainMenu"); } break; case ScreenState.MainMenu: mainMenu.Update(currentKey); if (mainMenu.exit) { switch (mainMenu.selection) { case 0: mainMenu = null; setScreen("Difficulty"); break; case 1: mainMenu = null; setScreen("Controls"); break; case 2: mainMenu = null; setScreen("Title"); break; } } break; case ScreenState.Difficulty: difficulty.Update(currentKey); if (difficulty.back) { difficulty = null; setScreen("MainMenu"); } else if (difficulty.exit) { int setting = difficulty.selection; difficulty = null; setScreen("Gameplay", setting); break; } break; case ScreenState.Gameplay: gameplay.Update(gameTime, currentKey); if (gameplay.exit) { if (gameplay.wins) { TimeSpan time = gameplay.TimeCount; gameplay = null; setScreen("Win", time); } else { int score = gameplay.Score; gameplay = null; setScreen("Lose", score); } } break; case ScreenState.Lose: lose.Update(currentKey); if (lose.exit) { lose = null; setScreen("MainMenu"); } break; case ScreenState.Win: win.Update(currentKey); if (win.exit) { win = null; setScreen("MainMenu"); } break; case ScreenState.Controls: controls.Update(currentKey); if (controls.exit) { controls = null; setScreen("MainMenu"); } break; } }
/// <summary> /// This function sets the screen state. /// </summary> /// <param name="stateString">state name</param> /// <param name="parameter">integer parameter</param> public void setScreen(String stateString, int parameter) { switch (stateString) { case "Gameplay": screenState = ScreenState.Gameplay; gameplay = new Gameplay(); gameplay.LoadContent(gameplayFont, parameter, gameplayTextures, playerTextures, playerSounds, enemyTextures); break; case "Lose": screenState = ScreenState.Lose; lose = new Lose(); lose.LoadContent(loseTexture, completeFont, parameter); break; } }