/// <summary> /// The base update loop calls update loops corresponding to the current game state /// </summary> /// <param name="gameTime">Provides a snapshot of timing values</param> protected override void Update(GameTime gameTime) { // Update the game time GameTime = gameTime; // Switch over the current state switch (State) { // Call the corresponding update functions for each menu case GameState.MainMenu: MainMenuScreen.Update(); break; case GameState.Instructions: InstructionsScreen.Update(); break; case GameState.ModeSelection: ModeSelectionScreen.Update(); break; // Game Modes case GameState.ClassicGameplay: // Create a new gameplay screen if it is null if (gameplayScreen == null) { gameplayScreen = new GameplayScreen(); } // Update the gameplay screen gameplayScreen.Update(); break; // The gameplay screens are identical and differ only in the EnemyManager (what enemies spawn) // and PlayerShip (how the player is controlled), meaning GameplayScreen can be used generically // in handling all operations regarding drawing and updating gameplay case GameState.FreeGameplay: if (gameplayScreen == null) { gameplayScreen = new GameplayScreen(); } gameplayScreen.Update(); break; } // Check to see if the game state is not in gameplay if (State != GameState.ClassicGameplay && State != GameState.FreeGameplay) { // Set the gameplay screen to null since the player ship controls and enemies are agnostic // to the current scene. The gameplay screen prevents updates to the player and enemies but // will still draw them unless the gameplay screen is reset entirely gameplayScreen = null; } // Update the root update loop base.Update(gameTime); }
public override void Update(GameTime theTime) { //Call the Engine's Update //if (engine != null) //{ // engine.Update(); //Renderer can only render if there is an engine... //NOTE: Should the renderer have an update? //Call the Game Renderer's Update if (gameplayScreen != null) { gameplayScreen.Update(theTime); } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// /// Select - Layer5 added by Matthew Baldock /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { //Allows game to exit. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } //particleEngine.EmitterLocation = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); particleEngine.Update(gameTime); //Update the current state switch (currentGameState) { case GameState.Login: login_menu.Update(gameTime); break; case GameState.MainMenu: main_menu.Update(gameTime); break; case GameState.Multiplayer: multiplayer_menu.Update(gameTime); break; case GameState.Options: options_menu.Update(gameTime); break; case GameState.Credits: credits_menu.Update(gameTime); break; case GameState.CreateLobby: create_lobby_menu.Update(gameTime); break; case GameState.LobbyBrowser: lobby_browser_menu.Update(gameTime); break; case GameState.Lobby: lobby_menu.Update(gameTime); break; case GameState.Playing: gameplayScreen.Update(gameTime); break; case GameState.Select: shipselectionScreen.update(); break; case GameState.ControlMenu: control_menu.Update(gameTime); break; default: break; } base.Update(gameTime); }