Game Development Reference
In-Depth Information
level version of the
Pac-Man
game loop during the gameplay state would look
something like what is shown in
Listing 1.1
.
Listing 1.1
Theoretical
Pac-Man
Game Loop
while
player.lives
> 0
// Process Inputs
JoystickData
j
= grab raw data from joystick
// Update Game World
update
player.position
based on
j
foreach
Ghost
g
in
world
if
player
collides with
g
kill either
player
or
g
else
update AI for
g
based on
player.position
end
loop
// Pac-Man eats any pellets
...
// Generate Outputs
draw graphics
update audio
loop
Note that the actual code for
Pac-Man
does have several different states, including
the aforementioned attract mode, so these states would have to be accounted for in
the full game's code. However, for simplicity the preceding pseudo-code gives a
representation of what the main game loop might look like if there were only one
state.