Time for action – implementing game states
Add declarations to the Game1 class for our GameState enum:
enum GameState { TitleScreen, Playing, PlayerDead, GameOver }; GameState gameState = GameState.TitleScreen;
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;
We currently have temporary code in the
LoadContent()
method that loads straight into the first level of the game. Replace the currentLoadContent()
method with the following:protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); TileMap.Initialize( Content.Load<Texture2D>(@"Textures\PlatformTiles")); TileMap.spriteFont = Content.Load<SpriteFont>...