Best Practive: How do you keep track of the player state?

Hi

I’ve been away from my game development project for a while, but recently attended Nordic Game Jam 2014 in Copenhagen and recruited a few more people, so its picking up again.

Anyway, to the topic: how do you keep track of the player state in your game?

I’ve currently got a PlayerControlState that implements the AnalogFunctionListener, StateFunctionListener (i’m using Lemur to great effect) which keeps track of the player input. Now, my game is (still) a tower defense/rts game, so I need to keep track of the state the player is in. I’m implementing a PlayerStateManager, which holds an entityId (a player will have one of these) and a PlayerStateEnum, which holds the following values:

Neutral,            //When the player first enters the game
EntitySelected,     //When an entity is selected
BuildMenuSelected,  //When the build menu is selected
BuildSelected,      //When the player selects something to build
AttackSelected      //When the player selects an attack from an entity

Everyone starts in Neutral. If you then select a unit, you enter the ‘entityselected’-state and your ui changes, and so forth. The PlayerStateManager will be a statemachine of sorts that is used by other systems to keep track of what is visibly or possible for the player. A keypress ‘B’ may be used to open the build-menu if you are in neutral, but if you are already in the buildmenuselected-state, it routes you to a specific buildselect-state.

Now, my question is a general one. Your inputlistener shouldn’t be bothered with the state you are in, perhaps it shouldn’t even be bothered by the consequences of the input (i.e. it detects the mouseclick, but simply reroutes the input to some other manager that figures out if something was clicked). How do you seperate this scheme of control in your code or rather, how do you implement input-to-actions in your game?

Kind regards,
Asser

Oh, I see that there are several ‘gems’ in the Lemur-sub-forum that may address my topic :slight_smile:

Oops.