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

The state of the game

Remember when we coded the pause button back in Chapter 4, Control Freak? We had to add some code that told the game whether it was active or paused. In fact, we defined the following enums:

enum GameState
{
  GS_Running,
  GS_Paused
};

These enums defined two game states: GS_Running, and GS_Paused. We then set the default game state to GS_Running in the StartGame function:

void StartGame()
{
  inputManager = new Input(hWnd);
  LoadTextures();
  m_gameState = GS_Running;
  
  srand(time(NULL));
  pickupSpawnThreshold = 5.0f;
  pickupSpawnTimer = 0.0f;
}

As long as the game state is set to GS_Running, then the game continues to cycle through the game loop, processing updates, and rendering the scene. However, when you click the pause button, the game state is set to GS_Paused. When the game is paused, we no longer update the game objects (that is, the robot, pickups, and enemies), but we do continue to render the scene and process the UI (user interface) so that buttons...

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 AU $24.99/month. Cancel anytime