Game Development Reference
In-Depth Information
Fig. 3.1
The game loop and its associated methods in the XNA game engine
3. Update : here we update the game world according to the time passed or according
to what the player is doing;
4. Draw : here we draw the game world onto the screen;
5. UnloadContent : here we can unload game assets if necessary;
6. Finalize : here we can perform any cleanup tasks needed, such as closing the net-
work connection or storing the highscore list.
Not all of these methods are required in a game. For example in BasicGame ,
only LoadContent , Update , and Draw are used. In addition, you will see two other
methods in the BasicGame program. One called BasicGame (lines 15-19) and one
called Main (lines 9-13). We are going to look into these parts of the program later
on in this chapter. For now, you can assume that the BasicGame part is also a kind of
initialization, similar to the Initialize method, that every class has. The Main part tells
the compiler which instructions to execute when the program starts, as we will see
later on.
In this topic, we are going to show you a lot of different ways of filling up all these
different methods with the tasks that you need to perform in your game. During this
process, we will also introduce a lot of programming techniques that are useful for
games (and, indeed, for a lot of other applications). In the following section, we are
going to look into the basic game application in more detail. Then, we are going to
fill this basic skeleton of a game with some additional instructions.
3.3 The Structure of a Program
3.3.1 The Basic Game Application in More Detail
In the early days, many computer programs only wrote text to the screen and did
not use any graphics at all. Such a text-based application is called a console appli-
cation. In addition to printing text to the screen, these applications could also read
text that a user entered on the keyboard. So, any communication with the user was
done in the form of question/answer sequences ('Do you want to format the hard
drive (Y/N?)'—'Are you sure (Y/N)?'—and so on). Before Windows-based OSes
became popular, this text-based interface was very common for text editing pro-
grams, spreadsheets, math applications, and even games. These games were called
 
Search WWH ::




Custom Search