Compare commits
No commits in common. "0c73e988769740f1586861a383338307f7d6769d" and "58ab5aa854268465807d3a3daec7cd39cc9286f9" have entirely different histories.
0c73e98876
...
58ab5aa854
72
__init__.py
72
__init__.py
@ -173,48 +173,42 @@ def cut_scene(sounds, soundName):
|
|||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
pygame.event.pump()
|
pygame.event.pump()
|
||||||
|
|
||||||
|
def obj_play(sounds, sound_name, player_pos, obj_pos):
|
||||||
def calculate_volume_and_pan(player_pos, obj_pos):
|
distance = player_pos - obj_pos
|
||||||
distance = abs(player_pos - obj_pos)
|
if abs(distance) > 9:
|
||||||
max_distance = 12 # Maximum audible distance
|
# The item is out of range, so play it at 0
|
||||||
if distance > max_distance:
|
left = 0
|
||||||
return 0, 0, 0 # No sound if out of range
|
right = 0
|
||||||
# Calculate volume (non-linear scaling for more noticeable changes)
|
|
||||||
volume = ((max_distance - distance) / max_distance) ** 1.5
|
|
||||||
# Determine left/right based on relative position
|
|
||||||
if player_pos < obj_pos:
|
|
||||||
# Object is to the right
|
|
||||||
left = max(0, 1 - (obj_pos - player_pos) / max_distance)
|
|
||||||
right = 1
|
|
||||||
elif player_pos > obj_pos:
|
|
||||||
# Object is to the left
|
|
||||||
left = 1
|
|
||||||
right = max(0, 1 - (player_pos - obj_pos) / max_distance)
|
|
||||||
else:
|
else:
|
||||||
# Player is on the object
|
# Calculate the panning based on the distance
|
||||||
left = right = 1
|
left = max(0, 1 - (distance / 9))
|
||||||
return volume, left, right
|
right = max(0, 1 + (distance / 9))
|
||||||
|
left = min(1, left)
|
||||||
def obj_play(sounds, soundName, player_pos, obj_pos):
|
right = min(1, right)
|
||||||
volume, left, right = calculate_volume_and_pan(player_pos, obj_pos)
|
|
||||||
if volume == 0:
|
|
||||||
return None # Don't play if out of range
|
|
||||||
# Play the sound on a new channel
|
# Play the sound on a new channel
|
||||||
x = sounds[soundName].play(-1)
|
channel = sounds[sound_name].play(-1)
|
||||||
# Apply the volume and pan
|
# Apply the position information to the channel
|
||||||
x.set_volume(volume * left, volume * right)
|
channel.set_volume(left, right)
|
||||||
return x
|
# Return the channel so that it can be used in the update and stop functions.
|
||||||
def obj_update(x, player_pos, obj_pos):
|
return channel
|
||||||
if x is None:
|
|
||||||
return None
|
|
||||||
volume, left, right = calculate_volume_and_pan(player_pos, obj_pos)
|
|
||||||
if volume == 0:
|
|
||||||
x.stop()
|
|
||||||
return None
|
|
||||||
# Apply the volume and pan
|
|
||||||
x.set_volume(volume * left, volume * right)
|
|
||||||
return x
|
|
||||||
|
|
||||||
|
def obj_update(channel, player_pos, obj_pos):
|
||||||
|
distance = player_pos - obj_pos
|
||||||
|
if abs(distance) > 9:
|
||||||
|
left = 0
|
||||||
|
right = 0
|
||||||
|
else:
|
||||||
|
# Calculate the panning based on the distance
|
||||||
|
left = max(0, 1 - (distance / 9))
|
||||||
|
right = max(0, 1 + (distance / 9))
|
||||||
|
left = min(1, left)
|
||||||
|
right = min(1, right)
|
||||||
|
# Apply the position information to the channel
|
||||||
|
channel.set_volume(left, right)
|
||||||
|
# Return the channel
|
||||||
|
return channel
|
||||||
|
|
||||||
|
soundData
|
||||||
def obj_stop(x):
|
def obj_stop(x):
|
||||||
# Tries to stop a playing object channel
|
# Tries to stop a playing object channel
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user