Code Examples
  Home arrow Code Examples arrow Page 4 - 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 - 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.

    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 2 hosted by Hostway
    Stay green...Green IT