From 8766290ccdbcd41cd124a27bc8e54c39d1ce5fdc Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Tue, 9 Sep 2025 00:01:53 -0400 Subject: [PATCH] Hopefully fixed a race condition where you could be killed while getting a cauldron and come back to life. Added sound for fill in grave and for survivor bonus. --- sounds/fill_in_grave.ogg | 3 +++ sounds/survivor_bonus.ogg | 3 +++ src/level.py | 11 ++++++----- src/player.py | 8 ++++++++ src/powerup.py | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 sounds/fill_in_grave.ogg create mode 100644 sounds/survivor_bonus.ogg diff --git a/sounds/fill_in_grave.ogg b/sounds/fill_in_grave.ogg new file mode 100644 index 0000000..9378bcf --- /dev/null +++ b/sounds/fill_in_grave.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9ec2c64fdd1f16bce0e2a940a8c898c72e7981801b32bc39464dd25e7e39dc0 +size 10469 diff --git a/sounds/survivor_bonus.ogg b/sounds/survivor_bonus.ogg new file mode 100644 index 0000000..c16f637 --- /dev/null +++ b/sounds/survivor_bonus.ogg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:015e83c994944e9c5a7e60769b1c92022cacf2a14395134d4b5cbb65ec314c6d +size 17166 diff --git a/src/level.py b/src/level.py index f48db9a..808936f 100644 --- a/src/level.py +++ b/src/level.py @@ -366,8 +366,8 @@ class Level: if not obj.is_in_range(self.player.xPos): continue - # Handle collectibles - if obj.isCollectible and self.player.isJumping: + # Handle collectibles (but not if player died this frame) + if obj.isCollectible and self.player.isJumping and not self.player.diedThisFrame: currentPos = round(self.player.xPos) if currentPos not in obj.collectedPositions: play_sound(self.sounds[f'get_{obj.soundName}']) @@ -400,7 +400,7 @@ class Level: self.player._coins = 0 self.levelScore += 2000 # Double score bonus instead of extra life speak("100 bone dust collected! Bonus score!") - play_sound(self.sounds['bone_dust']) + play_sound(self.sounds.get('survivor_bonus', 'bone_dust')) # Use survivor_bonus sound if available, fallback to bone_dust continue # Handle spiderweb - this should trigger for both walking and jumping if not ducking @@ -425,12 +425,13 @@ class Level: # Handle graves and other hazards if obj.isHazard and not self.player.isJumping: if isinstance(obj, GraveObject): - can_collect = obj.collect_grave_item(self.player) + can_collect = obj.collect_grave_item(self.player) and not self.player.diedThisFrame can_fill = obj.can_fill_grave(self.player) if can_collect: # Successfully collected item while ducking with shovel play_sound(self.sounds[f'get_{obj.graveItem}']) + play_sound(self.sounds.get('fill_in_grave', 'shovel_dig')) # Also play fill sound self.player.stats.update_stat('Items collected', 1) # Create PowerUp to handle the item effect item = PowerUp(obj.xPos, obj.yPos, obj.graveItem, self.sounds, 1, @@ -446,7 +447,7 @@ class Level: continue elif can_fill and obj.fill_grave(self.player): # Successfully filled empty grave with shovel - play_sound(self.sounds.get('shovel_dig', obj.soundName)) # Use dig sound if available + play_sound(self.sounds.get('fill_in_grave', 'shovel_dig')) # Use fill_in_grave sound if available, fallback to shovel_dig self.player.stats.update_stat('Graves filled', 1) # Stop grave's current audio channel if obj.channel: diff --git a/src/player.py b/src/player.py index d0a2249..61b9fe5 100644 --- a/src/player.py +++ b/src/player.py @@ -58,6 +58,9 @@ class Player: self.isInvincible = False self.invincibilityStartTime = 0 self.invincibilityDuration = 10000 # 10 seconds of invincibility + + # Death state tracking (to prevent revival after death in same frame) + self.diedThisFrame = False # Initialize starting weapon (rusty shovel) self.add_weapon(Weapon( @@ -92,6 +95,9 @@ class Player: def update(self, currentTime): """Update player state""" + # Reset death flag at start of each frame + self.diedThisFrame = False + if hasattr(self, 'webPenaltyEndTime'): if currentTime >= self.webPenaltyEndTime: self.moveSpeed *= 2 # Restore speed @@ -218,6 +224,8 @@ class Player: if self._health == 0 and old_health > 0: self._lives -= 1 + # Mark that player died this frame to prevent revival + self.diedThisFrame = True # Stop all current sounds before playing death sound pygame.mixer.stop() try: diff --git a/src/powerup.py b/src/powerup.py index 185d2e1..c36b234 100644 --- a/src/powerup.py +++ b/src/powerup.py @@ -74,6 +74,7 @@ class PowerUp(Object): # In survival mode, give bonus score instead level.levelScore += 2000 speak("Extra life found! Bonus score in survival mode!") + play_sound(self.sounds.get('survivor_bonus', 'get_extra_life')) # Use survivor_bonus sound if available else: player.extra_life() elif self.item_type == 'shin_bone': # Add shin bone handling