Understanding Game Theory


A video game is basically a movie. It consists of frames that change with a rate fast enough to make our brains think the pictures are continuous. Unlike a movie, though, the frames in a video game are composed on the fly. What happens next depends on a number of factors, including the user input.

The steps that make up the lifecycle of the game application is what differentiates a game from other Windows applications:

  1. Initialize: In this step you prepare for the game itself. This includes instantiating the game actors, drawing the initial playing ground, setting the timers, and so on.

  2. Start game loop: After the initialization, the game loop begins. The user (player) can start playing.

  3. Process user input: The user input is taken from the input device, be it keyboard, mouse, or joystick. In Doggie, this is the keyboard press that will move Doggie, the hero in the game.

  4. Perform the game logic: This includes performing the artificial intelligence in response to the user input. For example, in Doggie this is the step that determines the next location of the bad guys.

  5. Draw the next frame: Based on the user input in step 3 and the game logic in step 4, render the next frame. In Doggie, this is the redrawing of the game actors in their new locations.

  6. Synchronize display: Depending on the number of CPU cycles spent for steps 3 and 4, the next frame will be ready sooner or later than the previous frame. This results in a varying frame rate, something that is not acceptable. This step basically calculates the time spent on steps 3 and 4 and delays the computer action accordingly. In other words, if a frame must change every 30 milliseconds and steps 3 and 4 took 20 milliseconds, the thread that takes care of the frame drawing is put to sleep for 10 milliseconds. Consequently, if steps 3 and 4 took 10 milliseconds to complete, the thread is put to sleep for 20 seconds. This way, every frame will be changed in 30 milliseconds, making the game have a steady frame rate. Here is how it is done:

     While True   ' the use of t1 and t2 below is to make the frame rate steady   Get t1 (the start time)   Do Step 3 and 4   Draw the next frame (Step 5)   Get tw (the end time)   Process time = t2 - t1   If Process time < time for each frame,   wait until (time for each frame) elapses  End While Loop. Go back to Step 2. 

  7. Shut down: The game has reached its end. In this step, the application releases any resource and does some cleaning up. With .NET Framework, this is equipped with a garbage collector; however, you could skip this step safely.




Real World. NET Applications
Real-World .NET Applications
ISBN: 1590590821
EAN: 2147483647
Year: 2005
Pages: 82

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net