Game Development Reference
In-Depth Information
20 - Dodger
from pygame.locals import * instead of import pygame.locals .
Noticed that pressing down on one of the arrow keys not only sets one of the movement
variables to True , but it also sets the movement variable in the opposite direction to
False . For example, if the left arrow key is pushed down, then the code on line 93 sets
moveLeft to True , but it also sets moveRight to False . This prevents the player
from confusing the program into thinking that the player's character should move in two
opposite directions at the same time.
Here is a list of commonly-used constant variables for the key attribute of keyboard-
related Event objects:
Table 20-1: Constant Variables for Keyboard Keys
Pygame Constant
Variable
Keyboard
Key
Pygame Constant
Variable
Keyboard
Key
K_LEFT
Left arrow
K_HOME
Home
K_RIGHT
Right arrow
K_END
End
K_UP
Up arrow
K_PAGEUP
PgUp
K_DOWN
Down arrow
K_PAGEDOWN
PgDn
K_ESCAPE
Esc
K_F1
F1
K_BACKSPACE
Backspace
K_F2
F2
K_TAB
Tab
K_F3
F3
Return or
Enter
K_RETURN
K_F4
F4
K_SPACE
Space bar
K_F5
F5
K_DELETE
Del
K_F6
F6
K_LSHIFT
Left Shift
K_F7
F7
K_RSHIFT
Right Shift
K_F8
F8
K_LCTRL
Left Ctrl
K_F9
F9
K_RCTRL
Right Ctrl
K_F10
F10
K_LALT
Left Alt
K_F11
F11
K_RALT
Right Alt
K_F12
F12
104. if event.type == KEYUP:
105. if event.key == ord('z'):
106. reverseCheat = False
107. score = 0
108. if event.key == ord('x'):
109. slowCheat = False
Search WWH ::




Custom Search