Updated libstormgames. Fixed death sounds following player. Fixed volume keys in survival mode.

This commit is contained in:
Storm Dragon
2025-09-08 16:00:13 -04:00
parent 04067a4bb3
commit 2437e13604
5 changed files with 71 additions and 5 deletions

39
src/death_sound.py Normal file
View File

@@ -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

View File

@@ -257,10 +257,10 @@ class Enemy(Object):
# Award points # Award points
self.level.levelScore += totalPoints self.level.levelScore += totalPoints
# Play death sound if available using positional audio # Create a DeathSound object to play death sound at fixed position
deathSound = f"{self.enemyType}_dies" from src.death_sound import DeathSound
if deathSound in self.sounds: deathSoundObj = DeathSound(self.xPos, self.yPos, self.enemyType, self.sounds)
self.channel = obj_play(self.sounds, deathSound, self.level.player.xPos, self.xPos, loop=False) self.level.objects.append(deathSoundObj)
# Handle witch-specific drops # Handle witch-specific drops
if self.enemyType == "witch": if self.enemyType == "witch":

View File

@@ -272,6 +272,15 @@ class Level:
if caught: if caught:
return # Stop if player is dead 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 # Update bouncing items
for item in self.bouncing_items[:]: # Copy list to allow removal for item in self.bouncing_items[:]: # Copy list to allow removal
if not item.update(currentTime, self.player.xPos): if not item.update(currentTime, self.player.xPos):

View File

@@ -541,6 +541,10 @@ class WickedQuest:
# Handle events # Handle events
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.KEYDOWN: 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: if event.key == pygame.K_ESCAPE:
# Stop all sounds before exiting # Stop all sounds before exiting
pygame.mixer.stop() pygame.mixer.stop()
@@ -554,6 +558,20 @@ class WickedQuest:
speak("Run lock " + ("enabled." if self.runLock else "disabled.")) speak("Run lock " + ("enabled." if self.runLock else "disabled."))
elif event.key == pygame.K_BACKSPACE: elif event.key == pygame.K_BACKSPACE:
pause_game() 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: elif event.type == pygame.QUIT:
exit_game() exit_game()