Game Development Reference
In-Depth Information
76. bouncer['rect'].left += MOVESPEED
77. bouncer['rect'].top += MOVESPEED
78. if bouncer['dir'] == UPLEFT:
79. bouncer['rect'].left -= MOVESPEED
80. bouncer['rect'].top -= MOVESPEED
81. if bouncer['dir'] == UPRIGHT:
82. bouncer['rect'].left += MOVESPEED
83. bouncer['rect'].top -= MOVESPEED
84.
85. # check if the bouncer has move out of the window
86. if bouncer['rect'].top < 0:
87. # bouncer has moved past the top
88. if bouncer['dir'] == UPLEFT:
89. bouncer['dir'] = DOWNLEFT
90. if bouncer['dir'] == UPRIGHT:
91. bouncer['dir'] = DOWNRIGHT
92. if bouncer['rect'].bottom > WINDOWHEIGHT:
93. # bouncer has moved past the bottom
94. if bouncer['dir'] == DOWNLEFT:
95. bouncer['dir'] = UPLEFT
96. if bouncer['dir'] == DOWNRIGHT:
97. bouncer['dir'] = UPRIGHT
98. if bouncer['rect'].left < 0:
99. # bouncer has moved past the left side
100. if bouncer['dir'] == DOWNLEFT:
101. bouncer['dir'] = DOWNRIGHT
102. if bouncer['dir'] == UPLEFT:
103. bouncer['dir'] = UPRIGHT
104. if bouncer['rect'].right > WINDOWWIDTH:
105. # bouncer has moved past the right side
106. if bouncer['dir'] == DOWNRIGHT:
107. bouncer['dir'] = DOWNLEFT
108. if bouncer['dir'] == UPRIGHT:
109. bouncer['dir'] = UPLEFT
110.
111. # draw the bouncer onto the surface
112. pygame.draw.rect(windowSurface, WHITE, bouncer
['rect'])
113.
114. # check if the bouncer has intersected with any food
squares.
115. for food in foods[:]:
116. if doRectsOverlap(bouncer['rect'], food):
117. foods.remove(food)
118.
119. # draw the food
120. for i in range(len(foods)):
121. pygame.draw.rect(windowSurface, GREEN, foods[i])
122.
123. # draw the window onto the screen
124. pygame.display.update()
125. mainClock.tick(40)
Search WWH ::




Custom Search