Game Engine

Put the Engine to Work

Building the Blizzard Example
Building the Blizzard Example The game engine you created in this chapter allows you to create games without having to repeat boilerplate Windows code that is required of every Windows program. In this section, you use the game engine to create a new example called Blizzard that demonstrates the absolute minimum requirements of a Windows game. You'll quickly realize that the Blizzard example is very easy to understand because the game engine hides most of the mess associated with Windows programs.

You'll be glad to know that the Blizzard example isn't just a remake of the Skeleton example from Appendix C with the game engine thrown in. Because the game engine includes support for establishing a game loop complete with timed game cycles, it only makes sense to take advantage of that feature. Therfore, the Blizzard example demonstrates the power of game cycles and how they make it possible to get interesting graphical effects with little effort. More specifically, you find out how to rapidly draw graphical icons (snowflakes) at random locations on the game screen and see firsthand how the speed of the game loop impacts the performance of the game.
Writing the Program Code
The Blizzard example is divided into two source files: the Blizzard.h header file and the Blizzard.cpp source code file. Listing 2.8 contains the code for the Blizzard.h header file, which is relatively simple. Keep in mind that all the code for the Blizzard example is available on the accompanying CD-ROM.
Note - If you haven't yet installed a C++ development environment for Windows, please take a look at Appendix A, "Selecting a Game Development Tool." The accompanying CD-ROM includes source code files and project files for several popular development environments, such as Microsoft Visual C++ .NET, Borland C++Builder, and Bloodshed Dev-C++. It also includes executable versions of all the examples found in the book so that you can run them and test them out, even if you don't have a development tool installed yet.
Listing 2.8 The Blizzard.h Header File Simply Imports a Few Header Files and Declares the Important Global Game Engine Pointer
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-
// Blizzard Application
// C++ Header - Blizzard.h
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-
#pragma once
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-
// Include Files
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-
#include

#include "Resource.h"
#include "GameEngine.h"
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-
// Global Variables
//覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧-
GameEngine* g_pGame;
This header file includes the familiar windows.h, as well as Resource.h and GameEngine.h. After importing these header files, a global game engine pointer, g_pGame, is defined. This pointer is very important because it will provide the Blizzard example access to the game engine.

The Resource.h header file is somewhat of a helper file that establishes identifiers for all the resources used throughout the program. In this case, the only resources are two icons of different sizes (16x16 and 32x32). Listing 2.9 contains the code for the Resource.h header file for the Blizzard example.

Twitter

 

Developed by Virtualinfocom