Game Development Reference
In-Depth Information
Players never see the internal representation of the game world, but game developers do. When you
want to develop a game, you also need to design how to represent your game world internally. And part
of the fun of programming your own games is that you have complete control over this.
Another important thing to realize is that just like the real world, the game world is changing all the
time. Monsters move to different locations, the weather changes, a car runs out of gas, enemies
get killed, and so on. Furthermore, the player actually influences how the game world is changing!
So simply storing a representation of the game world in the memory of a computer isn't enough.
A game also needs to constantly register what the player is doing and, as a result, update this
representation. In addition, the game needs to show the game world to the player by displaying it on
the monitor of a computer, on a TV, or on the screen of a smart phone. The process that deals with
all this is called the game loop .
The Game Loop
The game loop deals with the dynamic aspects of a game. Lots of things happen while a game
is running. The players press buttons on the gamepad or touch the screen of their device, and a
constantly changing game world consisting of levels, monsters, and other characters needs to be
kept up to date. There are also special effects such as explosions, sounds, and much more. All these
different tasks that need to be handled by the game loop can be organized in two categories:
Tasks related to updating and maintaining the game world
Tasks related to displaying the game world to the player
The game loop continuously performs these tasks, one after the other (see Figure 2-1 ). As an
example, let's look at how you could handle user navigation in a simple game like Pac-Man. The
game world mainly consists of a labyrinth with a few nasty ghosts moving around. Pac-Man is
located somewhere in this labyrinth and is moving in a certain direction. In the first task (updating and
maintaining the game world), you check whether the player is pressing an arrow key. If so, you need
to update the position of Pac-Man according to the direction the player wants Pac-Man to go. Also,
because of that move, Pac-Man may have eaten a white dot, which increases the score. You need
to check whether it was the last dot in the level, because that would mean the player has finished
the level. Finally, if it was a larger white dot, the ghosts need to be rendered inactive. Then you need
to update the rest of the game world. The position of the ghosts needs to be updated, you have to
decide whether fruit should be displayed somewhere for bonus points, you need to check whether
Pac-Man collides with one of the ghosts (if the ghost isn't inactive), and so on. You can see that even
in a simple game like Pac-Man, a lot of work needs to be done in this first task. From now on, I'll call
this collection of different tasks related to updating and maintaining the game world the Update action.
Update the game world
Draw the game world
Figure 2-1. The game loop, which continuously updates and then draws the game world
 
Search WWH ::




Custom Search