Skip to content

Commit ed86b51

Browse files
committed
Add game over after 10 hits; works but two errors
1 parent 9a42b1d commit ed86b51

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pygame1_smallguy/small_guy_game.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,32 @@ def redrawGameWindow():
233233
clock.tick(27)
234234

235235
for event in pygame.event.get():
236-
if event.type == pygame.QUIT:
237-
running = False
236+
# if event.type == pygame.QUIT:
237+
# running = False
238238

239239
if event.type == pygame.USEREVENT:
240-
playSeconds -= 1
240+
playSeconds -= 1
241+
242+
if event.type == pygame.QUIT:
243+
running = False
241244
if playSeconds == 0:
242245
print("Time's up!")
243246
running = False
244247

248+
if hitNumber == 10:
249+
textGameOver = font.render(f"The goblin was hit 10 times, GAME OVER", 1, (0,255,0))
250+
print("game over")
251+
win.blit(textGameOver, (40, 25))
252+
i = 0
253+
while i < 200:
254+
pygame.time.delay(5)
255+
i += 1
256+
for event in pygame.event.get():
257+
if event.type == pygame.QUIT:
258+
i = 201
259+
pygame.quit()
260+
running = False
261+
245262
# the goblin collides with little guy ONLY when it is visible (= not destroyed yet)
246263
if goblin.visible == True:
247264
# the char collides with the goblin, calculated via the hitboxes, 5 hitnumber is deducted for every collision

0 commit comments

Comments
 (0)