Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
97 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Direct Input's
 A Breeze

 Timing and
 Windoze

 The Menu System
 Putting the
 Pieces Together

 Until Next Time

 Printable version

 


  The Series

 Part 1
 Part 2
 Part 3
 Part 4
 Part 5
 Part 6

 

Putting the Pieces Together

We are almost finished. Time to tie all of the little things we did together into one nice, neat package. So, we will start off with the game initialization routine.

Popup : Source Listing 9: Game_Init

This routine has had a little bit of alteration since you last saw it. First we added some calls. One to initialize our timing system, one for our menu system, and one for our Direct Input library. Also, we delete the loading game screen at the end of the routine. This is so we do not have the memory being used by our bitmap that will never be seen again. The main thing to notice though is the addition of a global variable called GameState. This variable holds the current state of the game. At then end of the game initialization routine we set this variable to the value GS_MENU. This lets our main game loop know what state to process. There are equates for all states in the game.

That is pretty much all that has been altered for the initialization. The shutdown code has been altered to call the shutdown routines for the Direct Input module, and for the menu module. The only other changes that we had to make were in the main game loop. Actually, we didn't have to change anything since the routine was empty the last time we saw it.

Here is the new main game loop.

Popup : Source Listing 10: Game_Init

The first thing you should notice about the code is that it is wrapped in calls to Start_Time() at the top, and Wait_Time() at the bottom. These calls control our frame rate. I have it set to 25 FPS, or 40 milliseconds. Thus, 25 FPS, or thereabouts, is the fastest our game will ever run.

Next, we have one large IF-ELSE statement that selects the proper game state based on our global variable that we dedicated for that purpose. So, whether we want to run a menu, or perform the death code, it is all right there to manage it.

Inside our GS_MENU and GS_FILE states is their corresponding code. They make the calls to their menu processing function and react based upon the value that is returned to them. Nothing fancy, just simple IF-ELSE statements here also.

That is what we have setup to execute. The new game loop is nothing more than a state manager. It simply looks at what the current state is and performs the code based on that state. All games have something very, if not exactly, similar in their core. This is the heart of the game and without it you would have nothing more than inactive modules, just like we had before this section.



Next : Until Next Time