From 37aa764d68798a754bc485c1b55d18898062dfbb Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 10 Sep 2020 13:44:51 -0400 Subject: [PATCH] Small update to object positioning. --- libstormgames.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/libstormgames.py b/libstormgames.py index dcdd3f6..51e251f 100755 --- a/libstormgames.py +++ b/libstormgames.py @@ -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 - 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 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 # 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 - 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 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 # Apply the position information to the channel x.set_volume(left, right) # return the channel