O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required