Added sound for when pumpkin hits you or lands near by.

This commit is contained in:
Storm Dragon
2025-02-01 02:57:01 -05:00
parent 7627543ed8
commit 3836f4a2c9
2 changed files with 13 additions and 4 deletions

View File

@@ -29,11 +29,17 @@ class Pumpkin:
return True
def stop_sound(self):
"""Stop the pumpkin's sound"""
def stop_sound(self, sounds, playerX):
"""Stop the pumpkin's sound and play splat if needed"""
if self.soundChannel:
obj_stop(self.soundChannel)
self.soundChannel = None
# Calculate volume and pan for splat sound based on final position
volume, left, right = calculate_volume_and_pan(playerX, self.x)
if volume > 0: # Only play if within audible range
channel = sounds["pumpkin_splat"].play()
if channel:
channel.set_volume(volume * left, volume * right)
def check_collision(self, player):
"""Check if pumpkin hits player"""
@@ -125,13 +131,13 @@ class Catapult(Object):
# Always update existing pumpkins
for pumpkin in self.activePumpkins[:]: # Copy list to allow removal
if not pumpkin.update(self.sounds, player.xPos):
pumpkin.stop_sound()
pumpkin.stop_sound(self.sounds, player.xPos)
self.activePumpkins.remove(pumpkin)
continue
if pumpkin.check_collision(player):
player.set_health(player.get_health() - pumpkin.damage)
pumpkin.stop_sound()
pumpkin.stop_sound(self.sounds, player.xPos)
pumpkin.isActive = False
self.activePumpkins.remove(pumpkin)
speak("Hit by a pumpkin!")