Game Development Reference
In-Depth Information
131. baddieAddCounter = 0
132. baddieSize = random.randint(BADDIEMINSIZE,
BADDIEMAXSIZE)
133. newBaddie = {'rect': pygame.Rect
(random.randint(0, WINDOWWIDTH-baddieSize), 0 -
baddieSize, baddieSize, baddieSize),
134. 'speed': random.randint
(BADDIEMINSPEED, BADDIEMAXSPEED),
135. 'surface':pygame.transform.scale
(baddieImage, (baddieSize, baddieSize)),
136. }
137.
138. baddies.append(newBaddie)
139.
140. # Move the player around.
141. if moveLeft and playerRect.left > 0:
142. playerRect.move_ip(-1 * PLAYERMOVERATE, 0)
143. if moveRight and playerRect.right < WINDOWWIDTH:
144. playerRect.move_ip(PLAYERMOVERATE, 0)
145. if moveUp and playerRect.top > 0:
146. playerRect.move_ip(0, -1 * PLAYERMOVERATE)
147. if moveDown and playerRect.bottom < WINDOWHEIGHT:
148. playerRect.move_ip(0, PLAYERMOVERATE)
149.
150. # Move the mouse cursor to match the player.
151. pygame.mouse.set_pos(playerRect.centerx,
playerRect.centery)
152.
153. # Move the baddies down.
154. for b in baddies:
155. if not reverseCheat and not slowCheat:
156. b['rect'].move_ip(0, b['speed'])
157. elif reverseCheat:
158. b['rect'].move_ip(0, -5)
159. elif slowCheat:
160. b['rect'].move_ip(0, 1)
161.
162. # Delete baddies that have fallen past the
bottom.
163. for b in baddies[:]:
164. if b['rect'].top > WINDOWHEIGHT:
165. baddies.remove(b)
166.
167. # Draw the game world on the window.
168. windowSurface.fill(BACKGROUNDCOLOR)
169.
170. # Draw the score and top score.
171. drawText('Score: %s' % (score), font,
windowSurface, 10, 0)
172. drawText('Top Score: %s' % (topScore), font,
windowSurface, 10, 40)
173.
174. # Draw the player's rectangle
175. windowSurface.blit(playerImage, playerRect)
Search WWH ::




Custom Search