Game Development Reference
In-Depth Information
Figure 20-1: A screenshot of the Dodger game in action.
Importing the Modules
1. import pygame, random, sys
2. from pygame.locals import *
The Dodger game will import the same modules that our previous Pygame games have:
pygame
,
random
,
sys
, and
pygame.locals
. The
pygame.locals
module
contains several constant variables that the Pygame library uses such as the event types
(
QUIT
,
KEYDOWN
, etc.) and keyboard keys (
K_ESCAPE
,
K_LEFT
, etc.). By using the
from pygame.locals import *
syntax, we can just type
QUIT
instead of
pygame.locals.QUIT
.
Setting Up the Constant Variables
There are several constant variables in this game. We use constant variables because the
variable name is much more descriptive than a number. For example, from the line
windowSurface.fill(BACKGROUNDCOLOR)
we know that the argument being sent