Fixed Game Over bug.
This commit is contained in:
1 parent
699bf1f064
commit
486e7f5187
12 files changed
+524
-12
No files matched your search
+15
-12
@@ -162,28 +162,28 @@ class Game:
|
||||
pygame.mouse.set_visible(False)
|
||||
pygame.display.set_caption("Maguro Cat Game")
|
||||
|
||||
self.wallpaper = pygame.image.load("wallpaper.jpg").convert()
|
||||
self.wallpaper = pygame.image.load("image_wallpaper.jpg").convert()
|
||||
self.wallpaper = pygame.transform.scale(self.wallpaper, SCREEN_SIZE)
|
||||
|
||||
self.cat_right_base = pygame.image.load("cat.png").convert_alpha()
|
||||
self.cat_right_base = pygame.image.load("image_cat.png").convert_alpha()
|
||||
|
||||
self.sushi_images = []
|
||||
for i in [1, 2, 4, 3]:
|
||||
img = pygame.image.load(f"sushi{i}.png").convert_alpha()
|
||||
img = pygame.image.load(f"image_sushi{i}.png").convert_alpha()
|
||||
img = pygame.transform.smoothscale(img, SUSHI_SIZE)
|
||||
self.sushi_images.append(img)
|
||||
|
||||
self.wasabi_img = pygame.image.load("wasabi.png").convert_alpha()
|
||||
self.wasabi_img = pygame.image.load("image_wasabi.png").convert_alpha()
|
||||
self.wasabi_img = pygame.transform.smoothscale(self.wasabi_img, SUSHI_SIZE)
|
||||
|
||||
self.cloud_base = pygame.image.load("cloud.png").convert_alpha()
|
||||
self.cloud_base = pygame.image.load("image_cloud.png").convert_alpha()
|
||||
self.cloud_img = pygame.transform.smoothscale(self.cloud_base, CLOUD_SIZE)
|
||||
|
||||
self.petal_base = pygame.image.load("petal.png").convert_alpha()
|
||||
self.petal_base = pygame.image.load("image_petal.png").convert_alpha()
|
||||
self.petal_img = pygame.transform.smoothscale(self.petal_base, PETAL_SIZE)
|
||||
self.petal_img_flipped = pygame.transform.flip(self.petal_img, True, False)
|
||||
|
||||
self.edamame_img = pygame.image.load("edamame.png").convert_alpha()
|
||||
self.edamame_img = pygame.image.load("image_edamame.png").convert_alpha()
|
||||
self.edamame_img = pygame.transform.smoothscale(self.edamame_img, SUSHI_SIZE)
|
||||
|
||||
self.music_file = "audio_music.mp3"
|
||||
@@ -322,8 +322,6 @@ class Game:
|
||||
self.pause(by_controller=False)
|
||||
elif event.key == pygame.K_q:
|
||||
quit_game()
|
||||
elif self.game_over and not self.paused:
|
||||
self.reset_game()
|
||||
if event.type == pygame.JOYBUTTONDOWN:
|
||||
if event.button in [7, 6]:
|
||||
if not self.game_over and not self.show_intro:
|
||||
@@ -472,7 +470,8 @@ class Game:
|
||||
self.draw_text(f"Score: {self.score}", (10, 10))
|
||||
|
||||
if self.game_over:
|
||||
self.draw_centered_multiline_text([f"Final Score: {self.score}", "Game Over!"], color=(255, 0, 0))
|
||||
big_font = pygame.font.Font(None, 96)
|
||||
self.draw_centered_multiline_text(["GAME OVER"], color=(255, 0, 0), font=big_font)
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
@@ -485,14 +484,18 @@ class Game:
|
||||
rect = surf.get_rect(center=(WIDTH // 2, HEIGHT // 2))
|
||||
self.screen.blit(surf, rect)
|
||||
|
||||
def draw_centered_multiline_text(self, lines, color=(255, 255, 255), line_spacing=10):
|
||||
def draw_centered_multiline_text(self, lines, color=(255, 255, 255), line_spacing=10, font=None):
|
||||
if font is None:
|
||||
font = self.small_font # fallback to default
|
||||
|
||||
total_height = 0
|
||||
rendered_lines = []
|
||||
for line in lines:
|
||||
surf = self.small_font.render(line, True, color)
|
||||
surf = font.render(line, True, color)
|
||||
rendered_lines.append(surf)
|
||||
total_height += surf.get_height() + line_spacing
|
||||
total_height -= line_spacing
|
||||
|
||||
y = (HEIGHT - total_height) // 2
|
||||
for surf in rendered_lines:
|
||||
rect = surf.get_rect(center=(WIDTH // 2, y + surf.get_height() // 2))
|
||||
|
||||
Reference in new issue
Block a user