Building the game class
We've done a good job at wrapping up the basic functionality of our window class, but that's not the only chunk of code in need of refactoring. In Chapter 1, It's Alive! It's Alive! – Setup and First Program, we've discussed the main game loop and its contents, mainly processing input, updating the game world and the player, and finally, rendering everything on screen. Cramming all of that functionality into the game loop alone is generally known to produce spaghetti code, and since we want to move away from that, let's consider a better structure that would allow this kind of behavior:
#include "Game.h" void main(int argc, void** argv[]){ // Program entry point. Game game; // Creating our game object. while(!game.GetWindow()->IsDone()){ // Game loop. game.HandleInput(); game.Update(); game.Render(); } }
The code above represents the entire content of our main.cpp
file...