From 2437e13604fff3aba3bb111930b02b208cc60136 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Mon, 8 Sep 2025 16:00:13 -0400 Subject: [PATCH] Updated libstormgames. Fixed death sounds following player. Fixed volume keys in survival mode. --- libstormgames | 2 +- src/death_sound.py | 39 +++++++++++++++++++++++++++++++++++++++ src/enemy.py | 8 ++++---- src/level.py | 9 +++++++++ wicked_quest.py | 18 ++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/death_sound.py diff --git a/libstormgames b/libstormgames index dcd204e..09421c4 160000 --- a/libstormgames +++ b/libstormgames @@ -1 +1 @@ -Subproject commit dcd204e476aa06b0ed8d8ba8ba23b0d28f04e14c +Subproject commit 09421c4bda82b3a93f209820abebee2ccb8b6572 diff --git a/src/death_sound.py b/src/death_sound.py new file mode 100644 index 0000000..bb9b6e3 --- /dev/null +++ b/src/death_sound.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +import pygame +from libstormgames import * +from src.object import Object + +class DeathSound(Object): + """Special object that plays enemy death sounds at fixed positions and self-removes.""" + + def __init__(self, x, y, enemyType, sounds): + # Initialize as a static object with the death sound name + deathSoundName = f"{enemyType}_dies" + super().__init__( + x, + y, + deathSoundName, + isStatic=True, + isCollectible=False, + isHazard=False + ) + + self.sounds = sounds + self.enemyType = enemyType + self.startTime = pygame.time.get_ticks() + + # Get the duration of the death sound if it exists + if deathSoundName in sounds: + self.soundDuration = sounds[deathSoundName].get_length() * 1000 # Convert to milliseconds + else: + self.soundDuration = 1000 # Default 1 second if sound doesn't exist + + def update(self, currentTime): + """Check if sound has finished playing and mark for removal.""" + if currentTime - self.startTime >= self.soundDuration: + # Sound has finished, deactivate and stop audio + self.isActive = False + if self.channel: + obj_stop(self.channel) + self.channel = None \ No newline at end of file diff --git a/src/enemy.py b/src/enemy.py index 3262b07..f560a24 100644 --- a/src/enemy.py +++ b/src/enemy.py @@ -257,10 +257,10 @@ class Enemy(Object): # Award points self.level.levelScore += totalPoints - # Play death sound if available using positional audio - deathSound = f"{self.enemyType}_dies" - if deathSound in self.sounds: - self.channel = obj_play(self.sounds, deathSound, self.level.player.xPos, self.xPos, loop=False) + # Create a DeathSound object to play death sound at fixed position + from src.death_sound import DeathSound + deathSoundObj = DeathSound(self.xPos, self.yPos, self.enemyType, self.sounds) + self.level.objects.append(deathSoundObj) # Handle witch-specific drops if self.enemyType == "witch": diff --git a/src/level.py b/src/level.py index 2cbf622..c470066 100644 --- a/src/level.py +++ b/src/level.py @@ -271,6 +271,15 @@ class Level: caught = obj.update(currentTime, self.player) if caught: return # Stop if player is dead + + # Update death sound objects + from src.death_sound import DeathSound + for obj in self.objects: + if isinstance(obj, DeathSound): + obj.update(currentTime) + + # Clean up inactive objects (including finished death sounds) + self.objects = [obj for obj in self.objects if obj.isActive] # Update bouncing items for item in self.bouncing_items[:]: # Copy list to allow removal diff --git a/wicked_quest.py b/wicked_quest.py index 32aee20..746f8fa 100755 --- a/wicked_quest.py +++ b/wicked_quest.py @@ -541,6 +541,10 @@ class WickedQuest: # Handle events for event in pygame.event.get(): if event.type == pygame.KEYDOWN: + # Check for Alt modifier + mods = pygame.key.get_mods() + altPressed = mods & pygame.KMOD_ALT + if event.key == pygame.K_ESCAPE: # Stop all sounds before exiting pygame.mixer.stop() @@ -554,6 +558,20 @@ class WickedQuest: speak("Run lock " + ("enabled." if self.runLock else "disabled.")) elif event.key == pygame.K_BACKSPACE: pause_game() + # Volume controls (require Alt) + elif altPressed: + if event.key == pygame.K_PAGEUP: + adjust_master_volume(0.1) + elif event.key == pygame.K_PAGEDOWN: + adjust_master_volume(-0.1) + elif event.key == pygame.K_HOME: + adjust_bgm_volume(0.1) + elif event.key == pygame.K_END: + adjust_bgm_volume(-0.1) + elif event.key == pygame.K_INSERT: + adjust_sfx_volume(0.1) + elif event.key == pygame.K_DELETE: + adjust_sfx_volume(-0.1) elif event.type == pygame.QUIT: exit_game()