02 07


Delphi Graphics and Game Programming Exposed! with DirectX For versions 5.0-7.0:The Anatomy of a Game                       Search Tips   Advanced Search        Title Author Publisher ISBN    Please Select ----------- Artificial Intel Business & Mgmt Components Content Mgmt Certification Databases Enterprise Mgmt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Productivity Apps Programming Langs Security Soft Engineering UI Web Services Webmaster Y2K ----------- New Arrivals









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 Start Sound Effects Games would tend to get boring without sound effects to accompany the actions of various game objects. The responsibility of this segment is to commence the output of various sound effects as warranted by the actions of both the user and the game controlled objects. Technically speaking, sound effect playback will probably be handled during other segments of the game loop. For example, when the user presses a button to fire a missile the user input retrieval segment will probably call a function that both starts the missile object as well as commences the playback of an appropriate sound effect. Other sound effects, such as idle background chatter or other appropriate noises that would be generated from non-interactive game objects, will probably be started when the artificial intelligence section makes one of these objects perform some action. Any other sound effects not handled by an appropriate segment, such as ambient sounds or user interface activation sounds, may be generated from this segment. We will see techniques for sound effect output in Chapter 9, Sound and Music. Start Music As with sound effects, music enhances the gaming experience, and this segment is responsible for starting musical output or changing the tune of the existing output. Again, music playback may be handled by another, more appropriate segment. However, music is commonly used to reflect the overall mood or state of the game. As such, this segment would be responsible for examining the current state as it would reflect from the user’s standpoint, and start or change the music as appropriate. For example, a neutral musical interlude may be output when the user is just flying along to the next waypoint. This could be changed, on the fly, to a more intense, urgent musical number when the user goes into combat. It could be changed to an even more intense score if the player or enemy is heavily damaged, and finally an appropriate tune could be played based on the user’s victory or defeat. This segment would need to perform the necessary actions to determine the current state of the game, playing a specific musical piece as appropriate. The chapter on sound and music contains examples of musical score playback techniques. Render the Next Frame This segment is responsible for the most important part of the game loop, that of displaying the current state of the game from the user’s perspective in graphical form. Depending on the complexity of the game, this may simply entail drawing two-dimensional bitmap images to the screen, or rendering a complex, realistic view based on the positions of three-dimensional models. Of all the segments in a game loop, this segment has the greatest variety of implementations. Like all game programming topics, some techniques are well documented, such as simple sprite output or even three-dimensional raycasting or rendering techniques. Other techniques, such as true three-dimensional space rendering, are trade secrets and are poorly documented, if at all. Typically, rendering a frame of animation starts by drawing the background. This may be as simple as a game board or something more complex, like a textured, scaled wall. Sprite images are then drawn over this background. All of this drawing generally takes place in an offscreen graphical buffer. After all drawing and rendering has been completed, this buffer is then blasted to the screen, at which point it becomes visible as the next frame of animation. As sprite positions are modified, their images drawn to reflect these new positions, and the results displayed to the screen in rapid succession, the illusion of animation is achieved. DirectX provides several methods for performing graphical output, both simplistic and complex. Check for Game End At some point, the current state of the game needs to be compared with a known state to see if a state change is in order. For example, if all of the player’s lives have been used up, the game is over. Additionally, when all of the enemy creatures have been eliminated or the exit is found, the current level has ended and it is time to advance to the next level of difficulty. Advanced games may potentially contain several states that affect how the overall game loop is processed. For example, when a level is completed, the game may go into a temporary intermission state where, instead of performing the normal gameplay animation, it displays a summary of the previous level’s accomplishments as well as the name or number of the next level being entered. A discussion of expanding the game loop to support different game states is covered below. Speed Delay The one constant in the computer industry is that machines will only get faster and faster as time marches on. Therefore, a game that plays at an acceptable speed today may be too fast to be humanly playable on a new machine six months from now. To ensure that the game runs at a specific speed on every machine, this segment determines if enough time has passed since the rendering of the last frame to constrain the game to a specific speed. One technique for controlling the speed of a game is to time the duration of the processing of the current animation frame. A starting time is recorded at the beginning of the game loop. At the end of the loop, this starting time is subtracted from the current time. If the result is less than a specific amount of time that will constrain the game speed to a certain rate, the execution is paused for the difference. This results in a game that should run at a constant speed on any machine equal to or faster than the minimum recommended system for the game. The sprite techniques chapter and other chapters throughout this book contain implementations of timing algorithms for controlling game speed. Note: To accommodate slower systems, some games perform timing tests to see how fast animation can be performed. If it is slower than a certain threshold, the game may compensate by dropping animation frames or turning off some features. The result will be a scaled-down, probably less attractive version of the game, but it has the advantage of running on older systems, which may be a selling point for the customer. Game States The game loop example detailed above provides the application with a framework that makes game animation and user input control easy and intuitive for the developer. However, it is not as robust as it needs to be for real-world applications. How many games jump right into the action immediately upon launching them? Most games display some sort of mission briefing or demonstration while waiting for the user to actually start a game. Typically, action games will also display some sort of information when a user has completed a level. Still others allow the user to input their name when a game has ended. 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.

Wyszukiwarka

Podobne podstrony:
od 02 07 09 do 10 07 09
r 02 07
Podano przyczyny nuklearnego blefu Husajna (02 07 2009)
TI 00 02 07 T pl
02 07 Engine Technology
26 02 07
02 07 Roboty na duzych wysokosciach wiezach masztach
Cios miecza w Afganistanie ruszyła ofensywa sił USA (02 07 2009)
R 02 07 (3)
TI 02 07 01 T pl
Wykład 02 (część 07) zasada prac wirtualnych dla odkształcalnych układów prętowych

więcej podobnych podstron