I have an InputController
which currently handles all user input, so it looks at button states and updates entity intentions according to some simple rules.
I'm looking to add a new state
to the game which essentially means displaying the player's inventory on screen. During this state I want the background to continue animating but want the user input to only interact with the inventory layer.
As the code stands right now the background will animate just fine under the inventory layer but the InputController
will continue to behave like the layer isn't there and attempt to map clicks etc. to the game world.
An easy solution would be to add simple conditional logic in the controller if (currentState == x)
but wondered if I could better utilise my existing game state machine. I have states such as game_loading
, in_game
, menu
etc.
The only ideas I can come up with is either calling out to something like state.HandleInput()
from inside the controller, that way the state is in control of what the player can and can't do but the downside is that input specific logic is being handled by a state
rather than input specific code, which I'm not comfortable with.
Alternatively, I could reverse that and get the state to be the entry point and then they call out to specific input classes. So something like inGameState.HandleInput()
calls out to inGameInputController
likewise with inventoryState
. This seems like the better approach.
I'm clearly not sure which way round the dependencies should orient. Am I missing a layer of abstraction somewhere? Or am I overcomplicating things?