Hopefully fixed level time and total time so they are reported correctly.

This commit is contained in:
Storm Dragon
2025-02-06 15:19:12 -05:00
parent 3c931b83ac
commit edad61a027

View File

@@ -12,6 +12,7 @@ class WickedQuest:
"""Initialize game and load sounds.""" """Initialize game and load sounds."""
self.sounds = initialize_gui("Wicked Quest") self.sounds = initialize_gui("Wicked Quest")
self.currentLevel = None self.currentLevel = None
self.gameStartTime = None
self.lastThrowTime = 0 self.lastThrowTime = 0
self.throwDelay = 250 self.throwDelay = 250
self.player = None # Will be initialized when first level loads self.player = None # Will be initialized when first level loads
@@ -148,7 +149,7 @@ class WickedQuest:
def game_loop(self): def game_loop(self):
"""Main game loop handling updates and state changes.""" """Main game loop handling updates and state changes."""
clock = pygame.time.Clock() clock = pygame.time.Clock()
startTime = pygame.time.get_ticks() levelStartTime = pygame.time.get_ticks()
currentLevelNum = 1 currentLevelNum = 1
while True: while True:
@@ -184,31 +185,33 @@ class WickedQuest:
# Check for death first # Check for death first
if self.currentLevel.player.get_health() <= 0: if self.currentLevel.player.get_health() <= 0:
if self.currentLevel.player.get_lives() <= 0: if self.currentLevel.player.get_lives() <= 0:
# Game over # Game over - use gameStartTime for total time
pygame.mixer.stop() pygame.mixer.stop()
self.display_game_over(pygame.time.get_ticks() - startTime) totalTime = pygame.time.get_ticks() - self.gameStartTime
self.display_game_over(totalTime)
return return
else: else:
pygame.mixer.stop() pygame.mixer.stop()
self.currentLevel.player._health = self.currentLevel.player._maxHealth
self.load_level(currentLevelNum) self.load_level(currentLevelNum)
self.currentLevel.player._health = self.currentLevel.player._maxHealth # Restore health levelStartTime = pygame.time.get_ticks() # Reset level timer
continue continue
# Handle collisions and check level completion # Handle collisions and check level completion
if self.currentLevel.handle_collisions(): if self.currentLevel.handle_collisions():
# Level completed # Level time is from levelStartTime
self.display_level_stats(pygame.time.get_ticks() - startTime) levelTime = pygame.time.get_ticks() - levelStartTime
self.display_level_stats(levelTime)
# Try to load next level
currentLevelNum += 1 currentLevelNum += 1
if self.load_level(currentLevelNum): if self.load_level(currentLevelNum):
# Reset timer for new level levelStartTime = pygame.time.get_ticks() # Reset level timer for new level
startTime = pygame.time.get_ticks()
continue continue
else: else:
# No more levels - game complete! # Game complete - use gameStartTime for total
totalTime = pygame.time.get_ticks() - self.gameStartTime
messagebox("Congratulations! You've completed all available levels!") messagebox("Congratulations! You've completed all available levels!")
self.display_game_over(pygame.time.get_ticks() - startTime) self.display_game_over(totalTime)
return return
clock.tick(60) # 60 FPS clock.tick(60) # 60 FPS
@@ -217,11 +220,12 @@ class WickedQuest:
"""Main game loop with menu system.""" """Main game loop with menu system."""
while True: while True:
choice = game_menu(self.sounds, "play", "instructions", "learn_sounds", "credits", "donate", "exit") choice = game_menu(self.sounds, "play", "instructions", "learn_sounds", "credits", "donate", "exit")
if choice == "exit": if choice == "exit":
exit_game() exit_game()
elif choice == "play": elif choice == "play":
self.player = None # Reset player for new game self.player = None # Reset player for new game
self.gameStartTime = pygame.time.get_ticks() # Set game start time here
if self.load_level(1): if self.load_level(1):
self.game_loop() self.game_loop()
elif choice == "learn_sounds": elif choice == "learn_sounds":