Code Examples
  Home arrow Code Examples arrow Page 9 - Creating an Engine for Games for Windows
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Creating an Engine for Games for Windows
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 41
    2004-10-13

    Table of Contents:
  • Creating an Engine for Games for Windows
  • What is a Game Engine?
  • Breaking a Game Down into Events
  • Developing a Game Engine
  • The GameEngine Class
  • Source Code for the WinMain Function
  • Initializing Variables
  • HandleEvent Method
  • Put the Engine to Work
  • Resource.h Header File
  • Testing the Finished Product

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    SamsThis chapter is from Beginning Game Programming, by Michael Morrison (Sams, ISBN: 0672326590). Check it out at your favorite bookstore today.

    Buy this book now.

    More Code Examples Articles
    More By Sams Publishing


     

    CODE EXAMPLES ARTICLES

    - Handling Animations and Bitmaps Using GDI+ f...
    - Download a Web Page using the WebClient
    - Creating a Chart using Data from a Database ...
    - The Basics of Charting with the MS Chart Con...
    - Searching Body Text with textRange: Enter th...
    - Searching Body Text with textRange: Building...
    - Searching Body Text with textRange, part 1: ...
    - First Steps in Programming
    - Programming in C
    - Quick Introduction to ASF,ASX, and Networkin...
    - SatView: Pointer Perfect, Part 2: Constructi...
    - SatView: Pointer Perfect, Part 1
    - Style Case Studies: Construction Unions
    - Creating an Engine for Games for Windows
    - Style Case Studies: Generic Callbacks





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT