how to handle all of the games input ?

Started by
1 comment, last by Brocketino 18 years, 9 months ago
how do some of you go about handling all of the input required to control the game.... do you just make one function and call it once per frame.. i am using direct input.. and i am basically just saying if this key is down do this.. from the main cpp file... .. i am thinking that my controlled units should do thier own check.. instead of me telling them to go..... now that i type that it almost seems necesarry.. is this making sense... i guess i just wanted some game input theory...
Advertisement
I would make seperate functions for related things.
For example:
Say you are make a first person shooter. You could have the main function and then have seperate ones to do other things like one to control the movement of the player (If Left Key go left ect.) and one for if spacekey pressed then shoot the gun. If you do this then your code will be well organized and a lot less confusing.
If you use DI you should get the state for all the keys and then update your main character based on that input, the controllable units could also, like you said, check for different states before updating.

  void CheckInput()  {    if(KEYDOWN(DIK_UP))    {     // Move forward     ...    }    if(KEYDOWN(DIK_SPACE))    {    // Fire weapon    ...    }}

This topic is closed to new replies.

Advertisement