New function for directional audio that needs to be good volume no matter position but indicate direction.
This commit is contained in:
parent
2f791da5b7
commit
173220d167
34
__init__.py
34
__init__.py
@ -635,6 +635,40 @@ def play_random_positional(sounds, soundName, player_x, object_x):
|
|||||||
volume * right * sfxVolume)
|
volume * right * sfxVolume)
|
||||||
return channel
|
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, 0)
|
||||||
|
else:
|
||||||
|
# Object is to the right of player
|
||||||
|
channel.set_volume(0, finalVolume)
|
||||||
|
return channel
|
||||||
|
|
||||||
def cut_scene(sounds, soundName):
|
def cut_scene(sounds, soundName):
|
||||||
"""Play a sound as a cut scene, stopping other sounds.
|
"""Play a sound as a cut scene, stopping other sounds.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user