Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
Q. I enjoyed this hour. How else can I improve my Python game script writing skills?
A. For further challenges, take a look at http://www.pyweek.org. This site runs game programming
contests twice a year to test your new-found Python game script writing skills.
Q. I want to use a gamepad in my game. Can PyGame handle that?
A. Yes, PyGame has an entire module, pygame.joystick, for interacting with gamepads,
trackballs, and joysticks.
Q. I’d like to have a picture as my game screen instead of a plain color. How can I make
that happen?
A. Instead of using the .fill method to fill the game screen with a plain color, you first load an
image, similarly to the way you loaded the Raspberry Pi image this hour. Next, you make sure
that image is as big as the game screen. Then you use the .blit method to draw it on the
screen first, before you .blit the other images. You can create some really cool game
backgrounds this way!

Workshop


Quiz


1. Panda3D is a sprite that you can use in a game script, and it comes pre-created in the
PyGame library. True or false?
2. What PyGame method allows you to add a slight pause (milliseconds) in the game?
3. Which PyGame method checks for two images or an image and a mouse pointer being at the
same place at the same time?
a. .collisionpoint
b. .collidepoint
c. .get_event

Answers


1. False. Panda3D is a full-feature framework for game development, including 3D graphics and
a game engine. You can use it to write games in C++ or Python.
2. The pygame.time.delay method allows you to pause a game for a specified number of
milliseconds.
3. Answer b is correct. The .collidepoint method tests the current image’s location on the
game screen and determines whether it has collided with another image or events location on
the game surface.
Free download pdf