Game Loop

// *************** MAIN GAME LOOP *******************
void main(void)
{
   // SECTION 1: initialization
   // init vars, build data structures, allocate memory,  
   // load graphics & sounds

   // SECTION 2: main event loop, erase-move-draw
   // here player selects options& controls the game experience
   // usually a single function that loops indefinitly
   while(game_running)
   { // SECTION 3: set game logic for next frame
      // erase all the objects or clear screen
      // loop thru 15 – 60 times per second

      // SECTION 4: process I/O events
      // mouse, joystick, keyboard, etc.

      // SECTION 5: game logic and further processing
      // based on player input manipulate the game
      // move the player, fire weapons, test for collisions
      // play music, animate background

      // SECTION 6: draw everything
      // draw new scene of rear buffer (double-buffering)
      // swap buffers

      // SECTION 7: synchronize to a constant frame rate
      // use a timer or Sleep() to control frame rate
   } // end while

   // SECTION 8: shutdown and bail
   // clean up memory, release resources
   // return everything to the way it was
   printf("\nG A M E O V E R \n\n");
}