Time for action – game over
Modify the declaration of the
GameStates enum
in the Game1 class to include the GameOver state:enum GameStates { TitleScreen, Playing, GameOver };
Add the following declarations to the Game1 class:
Vector2 gameOverLocation = new Vector2(200, 260); float gameOverTimer;
Modify the
Update()
method of Game1 by adding a newcase
section for theGameState.GameOver
state:case GameStates.GameOver: gameOverTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (gameOverTimer <= 0) { gameState = GameStates.TitleScreen; } break;
Modify the
if
statement in theDraw()
method of Game1 for theGameState.Playing
state fromif (gameState == GameStates.Playing)
to:if ((gameState == GameStates.Playing) || (gameState == GameStates.GameOver))
Add a new
if
statement for theGameState.GameOver
state to theDraw()
method, right before the call toBase.Draw(gameTime)
.if (gameState == GameStates.GameOver) { spriteBatch.Begin(); spriteBatch.DrawString...