Games and animations have several things in common. First, they’re fun! Second, they both involve drawing graphics on the screen and changing those graphics over time to give the illusion of motion.
GUI with Pygame
Timing It
Summary
Programming the cool apps in this chapter has given us the skills to do the following:
- Install and use the pygame module in our own Python programs.
- Explain the structure of a Pygame app, including the setup, game loop, and exit.
- Build a game loop that handles events, updates and draws graphics, and updates the display.
- Draw shapes to the screen using pygame.draw functions.
- Load images from disk with pygame.image.load().
- Draw images and objects to the screen with the blit() function.
- Create animations by drawing objects to the screen repeatedly in different locations.
- Make animations smooth, clean, and predictable using a pygame.time.Clock() timer’s tick() function to limit the number of frames per second in our animations.
- Check for collision detection by building the if logic to check for boundary cases, like a graphic hitting the edge of the screen.
- Control the horizontal and vertical speeds of moving objects on the screen by changing the amount of movement in the x- and y-directions from one frame to the next.