Character states

In order to correctly handle states, we will expand our character code to handle different states that can occur. Firstly, we need to identify the states, which are as follows:

  • Running state: This is the default state when the character is running on the ground
  • Jumping state: This is the state when we press a button to jump, but it should be limited so that we don't continue the jumping state when we are in the air
  • In air state: This is the state when the character is still in the air following a jump

In order to use these states, let's define them in ERGPlayer.h:

typedef enum playerState {
    
    playerStateRunning = 0,
    playerStateJumping,
    playerStateInAir
    
} playerState;

This code creates a new type of variable that is internally a usual ...

Get iOS 7 Game Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.