/// <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); }
/// <summary> /// The base draw loop handles drawing all draw loops corresponding to the current game state /// </summary> /// <param name="gameTime">Provides a snapshot of timing values</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); // Switch based on the current scene switch (State) { // Call each corresponding draw method case GameState.MainMenu: MainMenuScreen.Draw(spriteBatch); break; case GameState.Instructions: InstructionsScreen.Draw(spriteBatch); break; case GameState.ModeSelection: ModeSelectionScreen.Draw(spriteBatch); break; // If the gameplayScreen is not defined because the state updates asynchronously from // the update loop creating a new instance of gameplayScreen, ignore the current frame // and wait until the gameplayScreen is defined case GameState.ClassicGameplay: if (gameplayScreen != null) { gameplayScreen.Draw(spriteBatch); } break; case GameState.FreeGameplay: if (gameplayScreen != null) { gameplayScreen.Draw(spriteBatch); } break; } }
public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = screenWidth; graphics.PreferredBackBufferHeight = screenHeight; this.IsMouseVisible = true; Content.RootDirectory = "Content"; ScreenRectangle = new Rectangle(0, 0, screenWidth, screenHeight); Components.Add(new InputHandler(this)); stateManager = new GameStateManager(this); Components.Add(stateManager); TitleMenuScreen = new TitleMenuScreen(this, stateManager); InstructionsScreen = new InstructionsScreen(this, stateManager); GameScreen = new GameScreen(this, stateManager); GameOverScreen = new GameOverScreen(this, stateManager); WinnerScreen = new WinnerScreen(this, stateManager); stateManager.ChangeState(TitleMenuScreen); }
public void OnClickBackToTitleScreen() { TitleScreen.SetActive(true); CreditsScreen.SetActive(false); InstructionsScreen.SetActive(false); }
public void OnClickInstructions() { TitleScreen.SetActive(false); InstructionsScreen.SetActive(true); }
// Use this for initialization void Start () { instance = this; }
void Awake() { instance = this; }