Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenGL Game Development By Example

You're reading from   OpenGL Game Development By Example Design and code your own 2D and 3D games efficiently using OpenGL and C++

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783288199
Length 340 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Robert Madsen Robert Madsen
Author Profile Icon Robert Madsen
Robert Madsen
Stephen Madsen Stephen Madsen
Author Profile Icon Stephen Madsen
Stephen Madsen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

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 to look like the following code:

     case GameState::GS_GameOver:
     {
      gameOverScreen->Update(p_deltaTime);
      replayButton->IsActive(true);
      replayButton->Update(p_deltaTime);
      exitButton->IsActive(true);
      exitButton-&gt...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime