Jump to content
  • Advertisement
Sign in to follow this  
BlackJoker

Correct Input handling algorithm in game

This topic is 1865 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

Hello.

 

I faced with the following problem:

 

I want to make menu like in any other game - user assign buttons from the table to do different actions like moving forward/backward and other. So, any button could do ANY work now. And I don`t know which button do forward moving, for example. To know this I must write a ton of checks or switch with a ton of cases. 

 

Does someone have an algorithm for proper and easy handling such use case without megaton of if/else or switches, considering that this is a C++?

Share this post


Link to post
Share on other sites
Advertisement
I had this problem before. The solutin was a table.
On the API I was using at the time, keyboard input was made calling a device update method and than checking if a key is active by its code . for instance Readkey('a') would return true if a is active.

I made a wrapper for this API. Inside this class was a table that associates standard keys ( like up for walk and space for jump) with user defined keys. The class had a readkey(method) that receives a standard key and returns the status of the mapped user defined key, by calling the API method.

So, in my game code, I ever check the status of standar keys leting the translation work for the wrapper.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!