Game Development Reference
In-Depth Information
Most forms of input can be broken down into two categories: digital and analog.
A digital form of input is one that has a binary state: It can be either “on” or
“off.” For example, a key on a keyboard typically is digital—either the spacebar
is pressed, or it isn't. Most keyboards do not have an in-between state. An analog
form of input is one where there can be a range of values returned by the device.
One common analog device is a joystick, which will have a range of values in two
dimensions.
Whereas a keyboard may only have digital inputs, many input devices have both
analog and digital components. Take, for instance, the Xbox 360 controller: The
directional pad and the face buttons are digital, but the thumb sticks and triggers
are analog. Note that the face buttons on a controller are not always digital, as in
the case of the Playstation 2, but it's a typical implementation.
Oneotherconsideration forsometypesofgamesisthattheinputsystemmayneed
torespondto chords (multiple buttonpressesatonce)or sequences (aseriesofin-
puts). A genre where these are prevalent is the fighting game, which often has spe-
cial moves that utilize both chords and sequences. For example, in the later Street
Fighter games, if a Blanka player presses forward and all three punch or kick but-
tons at the same time (a chord), the character will quickly jump forward. Similarly,
all Street Fighter games have the concept of a fireball, which is performed with a
quarter circle forward followed by a punch button (a sequence). Handling chords
and sequences is beyond the scope of this chapter, but one approach is to utilize
a state machine designed to recognize the different special moves as they are per-
formed.
Digital Input
Other than for text-based games, standard console input (such as cin ) typically
is not used. For graphical games, the console usually is disabled altogether, so it
would be impossible to use standard input in any event. Most games will instead
use a library that enables much more granular device queries—one possibility for
a cross-platform title might be Simple DirectMedia Layer (SDL; www.libsdl.org ) .
WithlibrariessuchasSDL,itispossibletoquerythecurrentstateofadigitalinput
device. In such systems, it usually is possible to grab an array of Booleans that de-
scribe the state of every key on the keyboard (or any other digital input device). So
if the spacebar is pressed, the index corresponding to the spacebar would be set to
true. Memorizing which index numbers correspond to which keys would be tire-
some, sousually there is a keycode enumeration that maps each index to a specific
Search WWH ::




Custom Search