Game Development Reference
In-Depth Information
'
You
ll implement these interfaces in control classes to convert input from devices to
commands that can change the game state. Control objects in your game are guaran-
teed to receive device input in a standard and predictable way. Thus, it should be a
simple matter to modify and change the interface of your game by attaching new
control objects that care about any device you
ve installed.
The interface classes described previously are simple examples, and they should be
coded to fit the unique needs of your game. You can easily remove or add functions
at will, and not every game will use input exactly the same way.
'
Map Controls Directly to Controlled Objects
Don
t add parameters to distinguish between multiple joysticks or gamepads. A better solution is to
create controls that map directly to the object they are controlling. For example, if multiple gamepads
control multiple human drivers, the control code shouldn
'
t need to be aware of any other driver but the
one it is controlling. You could set all this up in a factory that creates the driver and the controller and
informs the input device code where to send the input from each gamepad.
'
If you follow a modular design, your game objects can be controlled via the same
interface, whether the source of that control is a gamepad or an AI character. For
example, the AI character could send commands like
into a car controller, where the human player touches a few gamepad keys, generating
translated events that eventually result in exactly the same calls but to a different car.
This design should always exist in any game where AI characters and humans are
essentially interchangeable. If humans and AI characters use completely different
interfaces to game objects, it becomes difficult to port a single-player game to multi-
player. You
brake 75%
or
steer 45%
'
ll soon discover that none of the
plugs
fit.
You
how to attach a mouse han-
dler and keyboard handler to a game view class, and you
'
ll see in Chapter 10,
User Interface Programming,
'
ll also see in Chapter 14,
how to implement a user interface using both the mouse and
the keyboard to move about a 3D scene.
3D Graphics Basics,
Using XInput or DirectInput
DirectInput was the de facto DirectX API for input devices such as the mouse, key-
board, joystick, game controllers, and force-feedback devices. It hasn ' t seen any major
development since DirectX 8, however. DirectX sits in between your application and
a physical device like a gamepad, video card, or sound card. For video and sound
systems, many things are handled directly by the hardware, such as a video card
'
s
ability to texture map a polygon. If the hardware doesn
t have that feature, it is sim-
ulated in software. This architecture is usually called a hardware abstraction layer,or
'
 
 
Search WWH ::




Custom Search