Game Development Reference
In-Depth Information
We also would like to give a message to the player that he/she got extra points in the
case of a double combination or a triple combination. For that, we want to show an
overlay for a couple of seconds. As a first step, let us load two overlays for that and
add them to the game world in the JewelJamGameWorld class:
SpriteGameObject doubleOverlay = new SpriteGameObject("spr_double", 1);
doubleOverlay.Position = new Vector2(800, 400);
this .Add(doubleOverlay);
SpriteGameObject tripleOverlay = new SpriteGameObject("spr_triple", 1);
tripleOverlay.Position = new Vector2(800, 400);
this .Add(tripleOverlay);
What we want to do now is that as soon as the player finds multiple combinations,
we want to show this overlay on the screen for a couple of seconds. In order to be
able to do that, we first need to understand a bit more about how we deal with time
in games.
18.3 Time in Games
Time is a very important concept in games. For example, it is used to measure
how fast a player executes a task, to update positions of objects according to their
velocity, to keep track of the last time that the player beat an enemy, to determine if it
is currently day or night in the game, and so on. In order to accommodate for these
things, a game engine will generally contain many classes to deal with different
aspects of time. Because time is so important in games, the game loop methods
in the Game class all have as a parameter a GameTime object. The game time does
not have to be the same as the time in the real world. In the game, time can go
three times as fast, or ten times as slow, or whatever the game designer wants. For
example, a game designer could decide that in a simulation game, time at night goes
much faster because not much happens at night. Also, the game time begins only
after the game has started. Furthermore, the game time can also be interrupted. For
example, if the player is moving the application window, the game time is paused
(whereas the real time continues).
When the game starts, the game time is zero. So: zero hours, zero minutes and
zero seconds will have passed. Every time the Update and Draw methods are exe-
cuted we get as a parameter a GameTime object. The GameTime class is made to give
a lot of information about how much time has passed. For example, you can retrieve
how much (game) time has passed since the last call to the Update method using the
ElapsedGameTime property. Also, you can retrieve how much game time has passed
since the start of the game using the TotalGameTime property. Similar properties ex-
ist for accessing the real time, such as ElapsedRealTime or TotalRealTime . Finally, the
GameTime object can also be used to check if the game is running slowly. This can
Search WWH ::




Custom Search