Compare commits

...

2 Commits

View File

@@ -635,6 +635,40 @@ def play_random_positional(sounds, soundName, player_x, object_x):
volume * right * sfxVolume)
return channel
def play_directional_sound(sounds, soundName, playerPos, objPos, centerDistance=3, volume=1.0):
"""Play a sound with simplified directional audio.
For sounds that need to be heard clearly regardless of distance, but still provide
directional feedback. Sound plays at full volume but pans left/right based on relative position.
Args:
sounds (dict): Dictionary of sound objects
soundName (str): Name of sound to play
playerPos (float): Player's x position
objPos (float): Object's x position
centerDistance (float): Distance within which sound plays center (default: 3)
volume (float): Base volume multiplier (0.0-1.0, default: 1.0)
Returns:
pygame.mixer.Channel: The channel the sound is playing on
"""
channel = sounds[soundName].play()
if channel:
# Apply volume settings
finalVolume = volume * sfxVolume * masterVolume
# If player is within centerDistance tiles of object, play in center
if abs(playerPos - objPos) <= centerDistance:
# Equal volume in both speakers (center)
channel.set_volume(finalVolume, finalVolume)
elif playerPos > objPos:
# Object is to the left of player
channel.set_volume(finalVolume, (finalVolume + 0.01) / 2)
else:
# Object is to the right of player
channel.set_volume((finalVolume + 0.01) / 2, finalVolume)
return channel
def cut_scene(sounds, soundName):
"""Play a sound as a cut scene, stopping other sounds.