Handling input
In the preceding code, you will notice a distinct lack of input handling code. This is because each game object will be responsible for handling its own input events. Most notable is the player-related game object that will handle movement input from the player.
There will also be a menu-related game object that will handle starting, pausing, and quitting the game and a camera-related object that will represent the minimap/radar that the player will be able to zoom in and out of. The point is that each object will handle its own input events. This next image illustrates this setup:
Figure 15.5: Handling input diagram
To achieve this, we will code an InputDispatcher
class of which, as we have seen in the main
function, there will be a single instance that will receive all the input events from the operating system and then dispatch them to several InputReceiver
class instances, which will have previously made themselves known (registered) to the InputDispatcher...