Jump to content
  • Advertisement
Sign in to follow this  
MTclip

how to handle all of the games input ?

This topic is 4893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
...
}
}



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!