Creating an Engine for Games for Windows - Developing a Game Engine
(Page 4 of 11 )
You now understand enough about what a game engine needs to accomplish that you can start assembling your own. In this section, you create the game engine that will be used to create all the games throughout the remainder of the book. Not only that, but also you'll be refining and adding cool new features to the game engine as you develop those games. By the end of the book, you'll have a powerful game engine ready to be deployed in your own game projects.
If you're accustomed to reading books that give you every little piece of code to type in and try out as you go, I should caution you that I don't list every line of code in this book. Certain pieces of code just aren't that important in the context of game programming (but are nonetheless required of all Windows programs), and I'd rather not burden you with long code listings when you can learn what you need to learn from a smaller snippet of code. The CD-ROM accompanying the book has the complete source code for every example in the book, so the code is there for you to sift through if you want to explore every little nuance. You'll also need the complete source code to build the examples; more on this later.
The point to this little discussion is that it isn't necessary for you to take in every line of code in order to learn how to reuse the code in this book to create your own games. Therefore, understand as you work through the rest of the book that the focus is on showing you the most interesting and significant code so that you have the knowledge to run with it and carry out your own game creations. Having said all of this, I do show you all the code for the game engine once I've presented the bits and pieces that go into it.
The Game Event Functions
The first place to start in creating a game engine is to create handler functions that correspond to the game events mentioned earlier in the chapter. When an event occurs in a game, the corresponding event handler function will be called, which gives your game a chance to respond accordingly. The following are these functions, which should make some sense to you because they correspond directly to the game events:
BOOL GameInitialize(HINSTANCE hInstance);
void GameStart(HWND hWindow);
void GameEnd();
void GameActivate(HWND hWindow);
void GameDeactivate(HWND hWindow);
void GamePaint(HDC hDC);
void GameCycle();
The first function, GameInitialize(), is probably the only one that needs special explanation simply because of the argument that gets sent into it. I'm referring to the hInstance argument, which is of type HINSTANCE. This is a Win32 data type that refers to an application instance. An application instance is basically a program that has been loaded into memory and is running in Windows. If you've ever used Alt+Tab to switch between running applications in Windows, you're familiar with different application instances. The HINSTANCE data type is a handle to an application instance, and it is very important because it enables a program to access its resources since they are stored with the application in memory.
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: The GameEngine Class >>
More Code Examples Articles
More By Sams Publishing