Structuring the Thomas Was Late code
One of the problems that has been quite pronounced in both projects so far is how long and unwieldy the code gets. OOP allows us to break our projects up into logical and manageable chunks called classes.
We will make a big improvement to the manageability of the code in this project with the introduction of an Engine class. Among other functions, the Engine class will have three private functions. They are input
, update
, and draw
. This should sound very familiar. Each of these functions will hold a chunk of the code that was previously all in the main
function. Each of these functions will be in a code file of its own, Input.cpp
, Update.cpp
, and Draw.cpp
respectively.
There will also be one public function in the Engine
class, which can be called with an instance of Engine
. This function is run
and will be responsible for calling input
, update
, and draw
, once for each frame of the game:
Furthermore, because we have abstracted the major parts of...