The local PyGame constants module, which contains top-level variables, was originally created to
make a game script writer’s life easier. One import statement and you have all the necessary
PyGame constants needed. To import these constants, you use a variation of the import command,
as shown here:
from pygame.locals import *
Finally, you need to initialize the PyGame modules. This is how you initialize all the PyGame
modules you have imported:
pygame.init()
Once you have all the modules and constants loaded and everything initialized, you can begin to use
these various PyGame items in your game script.
Setting Up the Game Screen
In setting up your game screen, you need to determine the following items:
Game screen size
Screen colors
Screen background
To set up the size of your game screen, you need to use the .display module. The syntax is as
follows:
Click here to view code image
pygame.display.set_mode(width, height)
You set the results to a variable name, such as GameScreen, to create a Surface object:
Click here to view code image
GameScreen = pygame.display.set_mode(1000,700)
A Surface object is a PyGame object that allows the representation of images on the computer’s
display. Think of it as a way to create a “playing surface” on which your game will be played.
Another nice thing about creating the game surface is that it will default to the best graphics mode on
your current hardware.
By the Way: Where You’re Located
To keep your bearings when you’re beginning to create a game, it’s a good idea to
make the game screen smaller than your computer’s display. This will allow you to see
the GUI underneath and provide a visual reference point. For example, while
developing the game, keep the game screen size to 600 pixels wide and 400 pixels
high. Once you have the game script working perfectly, you can change it to the full
computer display size.
You can use any colors on your screen that your computer display can handle. To set up your colors,
use the following syntax to add variables to your script:
Click here to view code image