Into the Platform Game Engine
Sunday, November 30th, 2008Hi everyone,
Today’s post talks will be about how to design the most basic parts of a platform game engine. On our last post, I finished a simple Map Editor, now it’s time to put Ninja Stick Figure into action!
Defining the Ninja Action States
Most of you are probably thinking about defining the most basic and generic objects (EG: the main character, enemies, bullets, items, etc.), but since this game is supposed to be simple, we’ll jump right into the main character, Ryuuhi, since I’m more interested in developing the platform engine. For a more complex and bigger project, this definitely wouldn’t be the best approach.
Anyway, the first thing I have to think about are the different states that our Ninja has:
![]()
Every state is self-explanatory so there’s not much to explain. Defining how states work is easy, IDLE happens when you don’t press any button, WALK when you press Left/Right, JUMP when you press the “Jump” button, and so on. For now, I won’t be using the ATTACK state since I’m only interested in how Little Ninja interacts with the terrain, not with other objects. Anyway, it’s important to associate an animation with each state, as well as a transition between states: for example, the character may go from IDLE to WALK, but can’t go directly from JUMP to WALK. Anyway, this can be done with a simple Enum:
enum NinjaAction
{
NJA_Idle = 0,
NJA_Walk = 1,
NJA_Turn = 2,
NJA_JumpStart = 3,
NJA_JumpHang = 4,
NJA_JumpEnd = 5,
}
Enums are very simple but work well on cases like this. This way, if I need to define another state or need to change its number for any reason, the rest of the code stays clean. For example, the IDLE animation would be ninjaAnimation[NJA_Idle], which is easier to understand compared to ninjaAnimation[0]. As for Jumping, three different states were defined: the part where Ryuuhi ascends (Start), the part where Ryuuhi doesn’t move and descends (Hang), and the part where he falls (End). In good theory, all states should have a generic outcome when you enter and exit a state, but as I said before, I’m more focused on game mechanics right now.
Note that Ryuuhi is facing to his LEFT on all the images. This means that, besides states, it is important to define the state’s direction too.















