Pausing and restarting the game
As we work on this game over the next three chapters, the code will obviously get longer and longer. So, now seems like a good time to think ahead and add a little bit more structure to our code. We will add this structure so that we can pause and restart the game.
We will add code so that, when the game is run for the first time, it will be in a paused state. The player will then be able to press the Enter key to start the game. Then, the game will run until either the player gets squished or runs out of time. At this point, the game will pause and wait for the player to press Enter so that they can restart the game.
Let's step through setting this up a bit at a time.
First, declare a new bool variable called paused outside the main game loop and initialize it to true:
// Variables to control time itself
Clock clock;
// Track whether the game is running
bool paused = true;
while (window.isOpen())
{
/*
...