Search Tips Advanced Search |
| Delphi Graphics and Game Programming Exposed with DirectX 7.0 by John Ayres Wordware Publishing, Inc. ISBN: 1556226373 Pub Date: 12/01/99
Search this book:
Previous | Table of Contents | Next
In Delphi applications, the developer has a number of areas where initialization code can be located. The main form’s OnCreate event is the most obvious location, but such code can also be placed in the OnActivate event or even in the initialization section of the unit. The initialization module typically contains code that is only run once at the beginning of application startup. Any variables that will be reset when a new game is started, such as the player’s score or starting level, should be modified in the game startup module.
| Caution: Pay attention to any dynamically created objects or dynamically allocated memory, and make sure to free these upon termination. Games that leak resources and cause the user to reboot the machine after play are not looked upon favorably.
#### Introduction The introduction module is responsible for introducing the player to the game and welcoming them into the game world. Typically, this takes the form of some sort of animated introduction. Most games, especially those constructed by professional game production houses, will display an elaborate animated sequence that gives a little background to the game and sets the overall mood. Some opening sequences are as good as action movie trailers, and may even feature live actors. The goal with these introductory animations is to immediately pull the player into the game world by eliciting the appropriate emotions and generally getting them into the right mood. Even a simple text display of a short story can be effective if written correctly. Usually, the game will provide a method by which the user can view the introduction again if they so desire, to review the overall game goals and objectives or to simply experience some cool animation again. While introductory animations are important for setting the mood and the story, it is equally important to remember that all introductions, no matter how cool, will become boring at some point. Some games will only show the introduction when the game is executed for the very first time. Introductory sequences will slow down users who play the game often, so it is important to remember to provide some method to skip the introduction, such as a keypress.
| Tip: Always allow users to bypass any animation sequence by pressing a hot key.
#### Game Startup The game startup module is responsible for two things. First, it should reset any variables that need to be initialized when a new game is started, such as a player’s score, their level, the number of lives left, etc. Second, game startup should allow the user to customize the game in any way supported. For example, game startup should include the code that allows the user to select which input device will be used, what side he’ll be playing, or other game-specific options. #### The Game Loop The game loop module is the focal point of the game application. It contains the primary game logic, and executes the code that creates the game environment and controls all game objects. Its primary responsibility is processing user input and rendering the game output. The game loop itself is a set of actions that are performed in rapid succession. These actions are performed over and over in a loop, updating the screen to reflect the current state of the game world. These actions are performed with or without any input from the user. Each pass through the game loop updates the screen one time, and represents one frame of animation. The code located in the game loop usually receives the most attention throughout the development cycle of a game, as this code must be highly optimized to run fast enough to achieve an acceptable game speed. What should be in the loop? That depends on the specific game, and varies on an individual basis. However, most game loops perform similar functions. The game loop is examined more closely below. #### Game Ending The game ending module is responsible for reporting to the player their overall game performance. This can take many forms, from a simple display of high scores to a summary of several different game statistics, or even an ending animation displaying a different scenario dependent upon whether the user won or lost. Whatever the method, the game ending module should let the user know that the game is over, and provide them with a choice to either start a new game or exit. If the user wishes to play another game, it should give control to the game startup module; otherwise it should execute the shutdown and exit module. #### Shutdown and Exit The shutdown and exit module is responsible for de-initializing variables and terminating the game application. It should free any dynamically allocated resources that were created in the initialization module, delete any temporary files, and generally ensure that the application will terminate without memory leaks or other artifacts. If the game offers the user a method by which it can be saved, it is usually a good idea to ask the user if they wish to save the current game before exiting. This will avoid frustrated and angry users who have spent several hours playing the game just to have their efforts destroyed by accidentally choosing the wrong option.
| Tip: Always ask the user if they wish to save the game before exiting (if game saving is supported).
This module should be reachable from several different points in the game. At any time, a user may want to end the game and exit the application, and this should be obtainable from the game startup, game loop, and game ending modules. Typically, several different methods are employed that allow the user to exit the game. For example, there is usually a button or menu item in the game startup and game ending modules that will exit the game. Hot keys are usually available from within the game loop that either give control to the shutdown and exit module or return the user to the game ending or game startup modules so that they can exit from there.
Previous | Table of Contents | Next

Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.