Game Development Reference
In-Depth Information
Input system
To understand how this all works together, let's look at the action of moving our ship
to the left. We have three different input systems for the game at the moment:
• Keyboard
• Touch
• GamePad
Certain actions on each of these input devices will all map to the same action: mov-
ing the player ship to the left. In our game the player could use any of these input
devices, so we need to be able to support them all.
First the system will check for input using all of the triggers. The input manager re-
trieves states from all of the input devices and then iterates through the triggers,
checking if any of the device states satisfy the triggers. If so, the associated action is
marked as triggered, ready for the game play logic to act on later. At some point all
of the actions are also cleared (usually at the beginning of the input update) to clean
the input state for a new update.
So now let's implement this system. First we'll define three classes, Trigger , Ac-
tion , and InputManager , which will work together to build the aforementioned
system.
Trigger
This is just a simple base class for the triggers we will define for different input types:
class Trigger
{
public:
virtual bool IsTriggered(InputManager *input)
= 0;
};
We'll look at how triggers work when we define one later.
Search WWH ::




Custom Search