Game Development Reference
In-Depth Information
and a third might be a view for a remote player over a network. They all get the same
state changes from the game logic they just do different things.
Applying the Game Architecture
It might seem weird to you at first that the code for the AI would communicate
through the same pathways and in exactly the same manner as a human being. Let
me give you a more concrete example. Let
'
s design a racing game using the game
logic and game view architecture, and we
ll also create two views: one for a human
player and one for an AI driver who will race with you on the track.
The game logic for a racing game will have the data that describes cars and tracks
and all the minute properties of each. For the car, you ' ll have data that describes
how weight is distributed, engine performance, tire performance, fuel efficiency, and
things like that. The track will have data that describes its shape and the properties of
the surface all along the route. You
'
ll also have a physics system that can calculate
what happens to cars in various states of acceleration and steering, how they respond
to the track, change in input controls, or even collisions with each other.
For inputs, the game logic cares about only four things for each car: steering, acceler-
ation, braking, and perhaps the emergency brake. If your cars have guns on them, like
we all wish, you would also have an input for whether the fire trigger is down. That
'
s
it; the game logic needs nothing else as input to get the cars moving around the track.
Outputs from the game logic will be state changes and events. This includes each
car ' s position and orientation and the position and orientation of the wheels in rela-
tion to the car
'
ll also have damage statistics
as an output. If your cars have guns, a state change could also be whether the weapon
is firing and how much ammo is left. Another important game state, especially the
way I play racing games, is collision events. Every time a collision happens, the
game logic sends an event with all the collision data. Events and state changes are
sent to game views.
The game view for the human has a lot of work to do to present the view of the game
state. It has to draw the scene from the player
'
s body. If the game supports damage, you
'
'
s selected point of view, send audio to
the speakers, spawn particle effects
especially when bad drivers like myself are
scraping down the guardrails
and rumble the force feedback controls. The view
also reads the state of the game controller and translates that into game logic com-
mands. A good example of this is to notice the right trigger pressed to full throttle,
and it sends the
Accelerator at 100%
command to the game view or changes in the
left thumbstick to
These commands are sent back to the game
logic. Take a look at Figure 2.2 to see what I mean:
Steer left at 50%.
 
 
Search WWH ::




Custom Search