Time for action – implementing game states

  1. Add declarations to the Game1 class for our GameState enum:
    enum GameState { TitleScreen, Playing, PlayerDead, GameOver };
    GameState gameState = GameState.TitleScreen;
  2. Still in the declarations section of the Game1 class, add vectors for the display position of our text items, a texture to hold the title screen image, and the delay before respawn when the player dies:
    Vector2 gameOverPosition = new Vector2(350, 300);
    Vector2 livesPosition = new Vector2(600, 580);
    
    Texture2D titleScreen;
    
    float deathTimer = 0.0f;
    float deathDelay = 5.0f;
  3. We currently have temporary code in the LoadContent() method that loads straight into the first level of the game. Replace the current LoadContent() method with the following: ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.