Game Development Reference
In-Depth Information
Chapter 21
Game State Management
21.1 Introduction
Normally, you do not immediately start playing when a game application starts. For
example, in the Jewel Jam game, we first saw a title screen before playing. More
complicated games will have menus for options, menus for selecting different lev-
els, screens to display the high score after finishing a level, a menu to select different
characters and attributes, and so on. In the Jewel Jam game, adding a title screen was
not that difficult, because the title screen itself had very little interaction. However,
when we look at the example in the previous chapter, you can see that already build-
ing a screen with a few options and controls can result in quite a lot of code. And you
can imagine that when we add more of these menus and screens to the game, that
it is going to be a pain to manage which objects belong to which screen and when
they should be drawn or updated. Generally, these different menus and screens are
called game states . In some programs, these are called scenes , and the object re-
sponsible for managing the scenes is the director . In some cases, a distinction is
made between game modes and game states. In that case, things like menus, the
main playing screen, and so on are game modes, whereas 'level finished' or 'game
over' are game states.
In this topic, we will follow a simplified paradigm and call everything game
states. In order to deal with these different game states, we are going to need a man-
ager . In this chapter, we will develop the main classes needed for such a structure,
and show how you can use it to display different menus and switch between them,
while keeping the code cleanly separated.
21.2 Basics of Managing Game States
When we want to deal properly with game states, we need to make sure of the
following:
 
Search WWH ::




Custom Search