<In this post I'm going to create the basic structure of the game, until now I had almost all the code included in the "rpg.cpp" file, but it was starting to get too big. I knew i needed to do a few things:>
- Clean up code, separate it into smaller parts.
- Create a Game State structure
- Use the new tileset!(see picture above)
- Create a folder to store images, move all references to the images to the new folder.
<The best way to understand it is to look at this diagram:>
<At the moment that's the project structure:>
<To create the game states and to divide the code into smaller parts, we are going to change the project structure to:>
<Now the "main" function include all the code, how i made the changes? First I created a file "gamestates.h" that is basically an enum to know in what state the game is:>
<File rpg.cpp has been totally rewritten:>
<Now it just contains a game class instance and a simple switch to select the game state and execute the right code (clean and neat), the game class is declared here:>
<Notice I moved all the variables as properties into the new class, and functions now are methods, notice too we have achieved two objectives: clean the code and split it into smaller parts, it is easier to understand and implement too, next objective is to code game.cpp >
The first function, the class initializer is this:
In the next posts I will show all the other methods.