In the game I am making, I have a struct game_obj that represents game objects, like bricks, trees, people, etc. These objects will either be controlled by the user input, or by AI. These objects will be able to move around as well.
right now i have something like this:
enum state{
/* brain states. if the state is STATE_PLAYER, do input handling instead of AI thinking.*/
STATE_PLAYER,
STATE_WARRIOR,
STATE_SNEAKY,
STATE_MAGE,
STATE_ATTACK,
STATE_RETREAT,
/* physical states*/
STATE_MOVE,
STATE_IDLE,
/* total number of states*/
STATE_LAST
};
struct game_obj{
int posx;
int posy;
float direction;
enum state brain_state;
enum state physical_state;
};
typedef void (* state_action)(struct game_obj * gobj);
state_action action_map[STATE_LAST];
void player_action(struct game_obj * gobj)
{
/* if pressing up, set direction to 90*/
}
void mage_action(struct game_obj * gobj)
{
/* do magey thinking and actions*/
}
void move_action(struct game_obj * gobj)
{
/* modify posx and posy according to direction*/
}
/*....*/
In this arrangement, I have two states. brain_states is for the AI, or the user if the state is STATE_PLAYER. physical_states are for movement. At first I tried to use only one state to do all of this, but couldn't do it and ended up seperating the mind and body into two states. Are two states enough, or too many? Is there a way to use only one state?






