By the Way: Experimental Modules
Notice the modules listed as “experimental.” You should not use them in any game you
plan to keep for a while. Those modules may change dramatically and could break
your game.
The PyGame library also includes object classes that make building a Python game much easier (see
Table 19.3).
TABLE 19.3 PyGame Object Classes
At this point, you may be a little overwhelmed. That is okay because this is an overwhelming topic.
Don’t worry. This hour will take you step by step through some of these modules and objects to get
you started writing games in Python.
Did You Know: Sprites
PyGame documentation often refers to the game pieces or characters in a game as
sprites. When it does, it is referring to the Sprite object class.
Loading and Initializing PyGame
To get started using the PyGame library in your Python game script, you need to do three primary
things:
- Import the PyGame library.
- Import local PyGame constants.
- Initialize the PyGame modules.
To import the PyGame library, you use the import command, like this:
import pygame
This imports all the PyGame modules and object classes. However, you can import individual
modules and classes, if desired.
By the Way: Speeding It Up
Once you have learned how to write Python game scripts, you can do a few things to
speed up your game. One of them is to import only the modules from the PyGame
library that you actually use in the script.