Game over

As the saying goes, all good things must come to an end. If the player doesn't meet the pickup threshold, the game will end, and the game over screen will be displayed. The player can choose to replay the game or exit.

The game over screen

Our last screen is the game over screen. By now, the process should be second nature, so let's try an abbreviated approach:

  1. Declare a pointer to the screen:
    Sprite* gameOverScreen;
  2. Instantiate the sprite in LoadTextures:
    gameOverScreen = new Sprite(1);
    gameOverScreen->SetFrameSize(800.0f, 600.0f);
    gameOverScreen->SetNumberOfFrames(1);
    gameOverScreen->AddTexture("resources/gameover.png", false);
    gameOverScreen->IsActive(true);
    gameOverScreen->IsVisible(true);
  3. Change the GS_GameOver case in the Update function ...

Get OpenGL Game Development By Example 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.