I'm (ultra) confuse about input managment. I've the global idea, but I can figure out how to implement something which fit my design (maybe because it's a lame one).
The context is a state based game. For the example, we wil define 3 states : MAIN_MENU, GAME_RUNNING, and GAME_CASTING_SPELL.
In this 3 states, the action "left-button mouse clic" will be handled differently :
- In the MAIN_MENU state, the input will change the state, from MAIN_MENU to GAME_RUNNING.
- In the GAME_RUNNING state, the input triggers a player action : cast a spell (let's say firebolt), which change the state from GAME_RUNNING to CASTING_SPELL.
- In the CASTING_SPELL state, the input gives informations for the spell, for example his target. You clic somewhere and the firebolt goes there. This input changes the state from CASTING_SPELL to GAME_RUNNING.
Somewhere I'll need a class (let's call it InputManager) which needs to know the state the game currently is, like this (pseudo-code):
(method called every tick
update(GameState state) {
switch(state) {
case MAIN_MENU :
if(mouse_leftbutton_clic)
*go to GAME state*
break;
case GAME_RUNNING :
if(mouse_leftbutton_clic)
*go to CASTING_SPELL state*
break;
case CASTING_SPELL :
if(mouse_leftbutton_clic)
*launch firebolt and go to GAME_RUNNING state*
break;
}
}
How do i link my classes together ? My input manager needs to know the existence of the other objects and classes to update their logic.
Plus, what happens when I want an event to trigger when the player presses 2 buttons at the same time ?
Should my input manager return an array defining the state of my keyboard and mouse input and instant T ?
What I said may be huge crap, I need a teacher
Thanks !