Small update to object positioning.

This commit is contained in:
Storm Dragon 2020-09-10 13:44:51 -04:00
parent 84a722bb8e
commit 37aa764d68

View File

@ -178,13 +178,15 @@ def obj_play(sounds, soundName, playerPos, objPos):
# The sound is out of range, so do nothing.
return None
distance = playerPos - objPos
if distance == 0:
left = 0.9
right = 0.9
else:
angle = math.radians(distance * 5)
left = math.sqrt(2)/2.0 * (math.cos(angle) + math.sin(angle))
right = math.sqrt(2)/2.0 * (math.cos(angle) - math.sin(angle))
if left < 0:
left *= -1
if right < 0:
right *= -1
if left < 0: left *= -1
if right < 0: right *= -1
# x is the channel for the sound
x = sounds[soundName].play(-1)
# Apply the position information to the channel
@ -198,13 +200,15 @@ def obj_update(x, playerPos, objPos):
obj_stop(x)
return None
distance = playerPos - objPos
if distance == 0:
left = 0.9
right = 0.9
else:
angle = math.radians(distance * 5)
left = math.sqrt(2)/2.0 * (math.cos(angle) + math.sin(angle))
right = math.sqrt(2)/2.0 * (math.cos(angle) - math.sin(angle))
if left < 0:
left *= -1
if right < 0:
right *= -1
if left < 0: left *= -1
if right < 0: right *= -1
# Apply the position information to the channel
x.set_volume(left, right)
# return the channel