Started work on sound positioning for objects.

This commit is contained in:
Storm Dragon 2020-09-09 19:50:56 -04:00
parent e8bf4f9565
commit 34d89ca54b

View File

@ -28,7 +28,7 @@ except ImportError:
except ImportError:
print("No other speech providers found.")
exit()
import math
import time
localConfig = configparser.ConfigParser()
@ -173,6 +173,25 @@ def cut_scene(sounds, soundName):
pygame.mixer.stop()
pygame.event.pump()
def obj_play(sounds, soundName, playerPos, objPos):
# attempt to stop sounds that go out of range.
if playerPos - objPos > 9 or playerPos - objPos < -9:
# The sound is out of range, so do nothing.
return
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()
# Apply the position information to the channel
x.set_volume(left, right)
# return the channel so that it can be used in the update and stop functions.
return x
def play_random(sounds, soundName, pause = False, interrupt = False):
key = []
for i in sounds.keys():