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
100 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
 MASM's HL Syntax
 Getting A Game
 Loop Running

 Connecting to
 Direct Draw

 Our DDraw Library
 Our Bitmap Library
 A Game... Kinda'
 Until Next Time

 Printable version

 


  The Series

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

 

A Game ... Well, Kinda'

The library routines are complete and we are now ready to plunge into our game code. We will start out by looking at the game initialization function since it is called first in our code.

Popup : Source Listing 8: Game_Init

This function plays the most important part in our game so far. In this routine we make the call to initialize Direct Draw. If this succeeds we load in our "Loading Game " bitmap file from disk. After that we lock the back buffer. This is very important to do since we will be accessing the memory directly. After it is locked we can draw our bitmap onto the surface and then unlock it. The final call in our procedure is to flip the buffers. Since we have the bitmap on the back buffer, we need it to be visible. Therefore, we exchange the buffers. The front goes to the back and the back goes to the front. At the completion of this call our bitmap is now visible on screen. One thing that may be confusing here is why we didn't load the bitmap into a Direct Draw surface. The reason is we will only be using it once so there was no need to waste a surface.

Next on our list of things to code is the Windows callback function itself. This function is how we handle messages in Windows. Anytime we want to handle a message the code will go in this function. Take a look at how we have it setup currently.

Popup : Source Listing 9: Game_Shutdown

Here we make the call to shutdown our Direct Draw library, and we also free the memory we allocated earlier for the bitmap. We could have freed the memory elsewhere and maybe next issue we will. But, things are a bit easier to understand when all of your initialization and cleanup code is in one place.

As you can see there isn't that much code in our game specific stuff. The majority resides in our modules, such as Direct Draw. This allows us to keep our code clean and any changes we may need to make later on a much easier since things aren't hard-coded inline. Anyway, the end result of what you have just seen is a Loading screen that is displayed until the user hits the escape key. And that ... primitive though it may be ... is our game thus far.





Next : Until Next Time