Updated libstormgames. Fixed death sounds following player. Fixed volume keys in survival mode.
This commit is contained in:
Submodule libstormgames updated: dcd204e476...09421c4bda
39
src/death_sound.py
Normal file
39
src/death_sound.py
Normal 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
|
||||
@@ -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":
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user