This weeks topic might be a simple and boring one since it’s only about the pause function of our game. However, I figured there might be some solutions to how things were done that might be a tad interesting so bare with me for a bit.
A pause function is probably not necessary in such a small game like ours but it’s mainly there to not force the player to die if in need of a unplanned toilet break or just need time to rest and regain some focus. This is how I solved it.
The update function in our game state class which you could say takes care of the in-game-loop is quite slimmed down and basically just calls for all our game’s different managers. This allowed me to easily implement a boolean check before running the mentioned updates.
If this pause bool was FALSE: run the updates.
If the pause bool was TRUE: don’t run the updates and instead present the pause menu on top of the game area. The pause menu only covered a smaller part of the game screen so I also added a grey rectangle with low opacity to give a greater sense of that the game play was actually inactive.
The buttons for the pause menu was created with the help of a struct that held a text for the button and an integer to serve as the button index. Each button was created in a loop which looped through a set amount of times for as many buttons that was needed and added to a vector array. At the moment we only needed two buttons (a Continue and a Quit button) which may have made the loop a bit unnecessary but it will make the implementation of further buttons easier in the future.
Maybe I also should mention that these buttons wouldn’t be clickable with the mouse but only accessed with a keyboard. An integer in the game state class was compared to the index in of the respective buttons as the user pressed the up and down arrows and adjusted the color of the current matching value to show which button that was selected. It would then perform the assigned task to the specific value when the activate button was pressed which in this case would be the return key.
See, this wasn’t that boring at all, was it?
Thanks for reading!