Introducing the main game loop
To keep any windowed application alive, the program must instigate an endless loop. We created one in Chapter 1, Hello Graphics Window: You’re On Your Way, to keep the graphics window open in the first exercise through the implementation of a while
loop. Since then, we’ve continued to use this design pattern in every application. This loop in a game is called the main game loop. Each loop produces one frame of graphics. In Pygame, this frame is pushed to the screen using the pygame.display.update()
or pygame.display.flip()
methods.
Thus far, our graphics applications have been very simple with very little happening within the loop – however, in a full-fledged game engine, the loop is quite complex and contains multiple significant events, as illustrated in Figure 6.1:
Figure 6.1: The main game loop and associated processes
After the application begins running, various items are initialized and loaded,...