Added Try Again on Game Over screen.
This commit is contained in:
1 parent
ea352b6bab
commit
7796336f3a
1 file changed
+16
-9
@@ -314,7 +314,9 @@ class Game:
|
|||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
quit_game()
|
quit_game()
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_ESCAPE:
|
if self.game_over:
|
||||||
|
self.reset_game()
|
||||||
|
elif event.key == pygame.K_ESCAPE:
|
||||||
if not self.game_over and not self.show_intro:
|
if not self.game_over and not self.show_intro:
|
||||||
if self.paused:
|
if self.paused:
|
||||||
self.unpause()
|
self.unpause()
|
||||||
@@ -323,7 +325,9 @@ class Game:
|
|||||||
elif event.key == pygame.K_q:
|
elif event.key == pygame.K_q:
|
||||||
quit_game()
|
quit_game()
|
||||||
if event.type == pygame.JOYBUTTONDOWN:
|
if event.type == pygame.JOYBUTTONDOWN:
|
||||||
if event.button in [7, 6]:
|
if self.game_over:
|
||||||
|
self.reset_game()
|
||||||
|
elif event.button in [7, 6]:
|
||||||
if not self.game_over and not self.show_intro:
|
if not self.game_over and not self.show_intro:
|
||||||
if self.paused:
|
if self.paused:
|
||||||
self.unpause()
|
self.unpause()
|
||||||
@@ -331,8 +335,6 @@ class Game:
|
|||||||
self.pause(by_controller=True)
|
self.pause(by_controller=True)
|
||||||
elif self.paused and event.button == 2:
|
elif self.paused and event.button == 2:
|
||||||
quit_game()
|
quit_game()
|
||||||
elif self.game_over and not self.paused:
|
|
||||||
self.reset_game()
|
|
||||||
|
|
||||||
if self.show_intro:
|
if self.show_intro:
|
||||||
if self.draw_intro():
|
if self.draw_intro():
|
||||||
@@ -470,8 +472,15 @@ class Game:
|
|||||||
self.draw_text(f"Score: {self.score}", (10, 10))
|
self.draw_text(f"Score: {self.score}", (10, 10))
|
||||||
|
|
||||||
if self.game_over:
|
if self.game_over:
|
||||||
big_font = pygame.font.Font(None, 96)
|
big_font = pygame.font.Font(None, 96)
|
||||||
self.draw_centered_multiline_text(["GAME OVER"], color=(255, 0, 0), font=big_font)
|
small_font = pygame.font.Font(None, 32)
|
||||||
|
self.draw_centered_multiline_text(["GAME OVER"], color=(255, 0, 0), font=big_font, line_spacing=0)
|
||||||
|
game_over_surf = big_font.render("GAME OVER", True, (255, 0, 0))
|
||||||
|
x_center = WIDTH // 2
|
||||||
|
y_start = (HEIGHT // 2) + game_over_surf.get_height() // 2 + 20
|
||||||
|
prompt_surf = small_font.render("Press any key to try again!", True, (255, 255, 255))
|
||||||
|
prompt_rect = prompt_surf.get_rect(center=(x_center, y_start + prompt_surf.get_height() // 2))
|
||||||
|
self.screen.blit(prompt_surf, prompt_rect)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
@@ -486,8 +495,7 @@ class Game:
|
|||||||
|
|
||||||
def draw_centered_multiline_text(self, lines, color=(255, 255, 255), line_spacing=10, font=None):
|
def draw_centered_multiline_text(self, lines, color=(255, 255, 255), line_spacing=10, font=None):
|
||||||
if font is None:
|
if font is None:
|
||||||
font = self.small_font # fallback to default
|
font = self.small_font
|
||||||
|
|
||||||
total_height = 0
|
total_height = 0
|
||||||
rendered_lines = []
|
rendered_lines = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@@ -495,7 +503,6 @@ class Game:
|
|||||||
rendered_lines.append(surf)
|
rendered_lines.append(surf)
|
||||||
total_height += surf.get_height() + line_spacing
|
total_height += surf.get_height() + line_spacing
|
||||||
total_height -= line_spacing
|
total_height -= line_spacing
|
||||||
|
|
||||||
y = (HEIGHT - total_height) // 2
|
y = (HEIGHT - total_height) // 2
|
||||||
for surf in rendered_lines:
|
for surf in rendered_lines:
|
||||||
rect = surf.get_rect(center=(WIDTH // 2, y + surf.get_height() // 2))
|
rect = surf.get_rect(center=(WIDTH // 2, y + surf.get_height() // 2))
|
||||||
|
|||||||
Reference in new issue
Block a user