Game Development Reference
In-Depth Information
20 - Dodger
arguments for pygame.display.set_mode() are not two integers but a tuple of
two integers.
On line 46, the caption of the window is set to the string 'Dodger' . This caption will
appear in the title bar at the top of the window.
In our game, we do not want the mouse cursor (the mouse cursor is the arrow that moves
around the screen when we move the mouse) to be visible. This is because we want the
mouse to be able to move the player's character around the screen, and the arrow cursor
would get in the way of the character's image on the screen. We pass False to tell Pygame
to make the cursor invisible. If we wanted to make the cursor visible again at some point in
the program, we could call pygame.mouse.set_visible(True) .
Fullscreen Mode
The pygame.display.set_mode() function has a second, optional parameter that
you can pass to it. The value you can pass for this parameter is pygame.FULLSCREEN ,
like this modification to line 45 in our Dodger program:
45. windowSurface = pygame.display.set_mode((WINDOWWIDTH,
WINDOWHEIGHT), pygame.FULLSCREEN)
Passing pygame.FULLSCREEN will make the program take up the entire space of the
screen. It will still be WINDOWWIDTH and WINDOWHEIGHT in size for the windows width
and height, but the image will be stretched larger to fit the screen. There may be wasted
space along the top and bottom (or the left and right) sides of the screen if you did not set
the window size in proportion with the screen's resolution.) To avoid the wasted space, you
should set the size of the window to a 4:3 ratio (for every 4 pixels of width, have 3 pixels
for height).
If you do not use the fullscreen mode, then you do not need to worry about using a 4:3
ratio for the width and height. Just use whatever width and height works best for your
game.
49. # set up fonts
50. font = pygame.font.SysFont(None, 48)
We need to create a Font object to use when we create a Surface object with the
image of text drawn on it. (This process is called "rendering".) We want to create a generic
font, so we will use the default Font object that the pygame.font.SysFont()
constructor function returns. We pass None so that the default font is used, and we pass 48
so that the font has a size of 48 points.
52. # set up sounds
Search WWH ::




Custom Search