diff --git a/libstormgames.py b/libstormgames.py index efc8a03..f9887ad 100755 --- a/libstormgames.py +++ b/libstormgames.py @@ -174,7 +174,6 @@ def cut_scene(sounds, soundName): 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 @@ -186,12 +185,34 @@ def obj_play(sounds, soundName, playerPos, objPos): if right < 0: right *= -1 # x is the channel for the sound - x = sounds[soundName].play() + x = sounds[soundName].play(-1) # 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 obj_update(x, playerPos, objPos): + # attempt to stop sounds that go out of range. + if playerPos - objPos > 9 or playerPos - objPos < -9: + obj_stop(x) + 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 + # Apply the position information to the channel + x.set_volume(left, right) + +def obj_stop(x): + # Tries to stop a playing object channel + try: + x.stop() + except: + pass + def play_random(sounds, soundName, pause = False, interrupt = False): key = [] for i in sounds.keys():