Implementing an abstraction layer for supporting multiple input methods
In this recipe we are going to rework the code produced in Handling keyboard and mouse input. We are going to add an abstraction layer to the input handling sections of our code to hide away the specifics of the input device being used. This means that the gameplay code that controls animation and movement of the panda will not be handling any specific keys being pressed. Instead, there will be just a set of unified events for the actions the panda should be able to perform.
The reason for adding such a layer can already be found in the title of this recipe. We want to generalize our gameplay code to be able to support more input devices than just the classic keyboard and mouse combination. Further down in this chapter we will use this approach to add gamepad support to our demo, for example. We could also use the approach of this recipe as a starting point for implementing artificial intelligence for a game—why not let...