Pages

Thursday, August 18, 2011

<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.

<Before starting with the updates to the code I'm going to explain what the game states are and what i expect to do with them>

<The best way to understand it is to look at this diagram:>

<We have many "Screens" that represent different game states, in every game state the game acts in a different way (different input, output and logic), what we need is to have a way to store where the game is, so we can launch the code that will handle that particular state>

<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:>

<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 >