MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / gameOverAnimation

Function gameOverAnimation

src/gamesbyexample/pygame_games/simulate.py:213–235  ·  view source on GitHub ↗
(color=WHITE, animationSpeed=50)

Source from the content-addressed store, hash-verified

211
212
213def gameOverAnimation(color=WHITE, animationSpeed=50):
214 # play all beeps at once, then flash the background
215 origSurf = DISPLAYSURF.copy()
216 flashSurf = pygame.Surface(DISPLAYSURF.get_size())
217 flashSurf = flashSurf.convert_alpha()
218 BEEP1.play() # play all four beeps at the same time, roughly.
219 BEEP2.play()
220 BEEP3.play()
221 BEEP4.play()
222 r, g, b = color
223 for i in range(3): # do the flash 3 times
224 for start, end, step in ((0, 255, 1), (255, 0, -1)):
225 # The first iteration in this loop sets the following for loop
226 # to go from 0 to 255, the second from 255 to 0.
227 for alpha in range(start, end, animationSpeed * step): # animation loop
228 # alpha means transparency. 255 is opaque, 0 is invisible
229 checkForQuit()
230 flashSurf.fill((r, g, b, alpha))
231 DISPLAYSURF.blit(origSurf, (0, 0))
232 DISPLAYSURF.blit(flashSurf, (0, 0))
233 drawButtons()
234 pygame.display.update()
235 FPSCLOCK.tick(FPS)
236
237
238

Callers 1

mainFunction · 0.85

Calls 2

drawButtonsFunction · 0.85
checkForQuitFunction · 0.70

Tested by

no test coverage detected