The control situation of a game can be represented as a state machine. Eg:
Each state has different requirements, in the menu state, WSAD won’t do anything, in the game state, clicking in the middle of the screen won’t quit.
One way to deal with this is to have each object able to check the control state: ie polling some dictionary of active inputs, and having a player module determine what object is currently polling the control system, but then it can’t handle transitions from playing to the menu easily. This is what most blender games use (I think)
This is ‘object in control’
Another way is to have the game state integrated into the control system, So for instance, there is a global property called ‘gamestate’, which can be set to ‘menu’ or ‘car’ or ‘human’ (or ‘dead’). The control system then mind-controls the objects and gets them to move.
This is ‘game in control’
The problem with both of these is that they require tight coupling. In the first method, the player needs to know about the control system. In the second method, the control system needs to know about the player.
So, the question is:
As far as I can see, there are multiple parts:
- Mapping keys to abstract ‘actions’ (eg ‘SPACE_KEY’ → ‘shooting’)
- Mapping actions to physical activities (eg ‘shooting’ → ‘addObject(bullet)’)
Both of these need to be changed for each ‘game state,’ and I’m getting confused about how to handle all this.
Note that I am talking at a very abstract level. I’m not asking for code, but rather system design.