Creating an Engine for Games for Windows - Put the Engine to Work
(Page 9 of 11 )
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.
Note - All the code for the Blizzard example—including project files for Visual Studio/C++ .NET, Borland C++Builder, and Bloodshed Dev-C++—is located on the accompanying CD-ROM. I encourage you to use the project files that I've provided because they contain the necessary settings for the examples to compile and link properly. Windows programs (especially games) can sometimes be tricky to set up in terms of getting the compiler and linker settings just right.
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 <windows.h>
#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.
This chapter is from Beginning Game Programming, by Michael Morrison (Sams, ISBN: 0672326590). Check it out at your favorite bookstore today.
Buy this book now. |
Next: Resource.h Header File >>
More Code Examples Articles
More By Sams Publishing