Game Development Reference
In-Depth Information
Real Time and Game Time
It is very important to distinguish real time , the amount of time that has elapsed
in the real world, from game time , which is how much time has elapsed in the
game's world. Although there may often be a 1:1 correspondence between real
time and game time, that certainly is not always the case. Take, for instance, a
game in a paused state. Although a great deal of time might be elapsing in the real
world, the game time is stopped entirely. It's not until the game is unpaused that
the game time starts updating again.
Thereareseveralotherinstanceswheretherealtimeandgametimemightdiverge.
Forexample,toallowformorenuancedgunfights, Max Payne usesa“bullettime”
gameplay mechanic that reduces the speed of the game. In this case, the game time
must update at a substantially slower rate than actual time. On the opposite end of
the spectrum, many sports games feature sped-up time. In a football game, rather
than requiring a player to sit through 15 full minutes per quarter, the game may
update the clock twice as fast, so it actually only takes half the time. And some
games may even have time progress in reverse. For example, Prince of Persia:
The Sands of Time featured a unique mechanic where the player could rewind the
game time to a certain point.
With all these different ways real time and game time might diverge, it's clear that
our video game's loop should take elapsed game time into account. The following
section discusses how our game loop might be updated to account for this require-
ment.
Logic as a Function of Delta Time
Early games were often programmed with a specific processor speed in mind. A
game's code might be written explicitly for an 8 MHz processor, and as long as it
worked properly it was considered acceptable. In such a setup, code that updates
the position of an enemy might look something like this:
Click here to view code image
// Update x position by 5 pixels
enemy.position.x += 5
If this code moves the enemy at the desired speed on an 8 MHz processor, what
happens on a 16 MHz processor? Well, assuming that the game loop now runs
twice as fast, that means that the enemy will also now move twice as fast. This
could be the difference between a game that is challenging and one that is impos-
Search WWH ::




Custom Search