diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-01-28 11:48:41 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2018-01-28 11:48:41 +0700 |
commit | 1b2dc5e1692e9d7b010aa9822d228f4fc3c5ac1e (patch) | |
tree | cc0c976fb57493055b489654cb4085548d18c45a /brutalmaze/misc.py | |
parent | fca23ea3ce86461f1b970afeb87fcbf5c3a124d3 (diff) | |
download | brutalmaze-1b2dc5e1692e9d7b010aa9822d228f4fc3c5ac1e.tar.gz |
Make all sound playing fail-safe 0.4.2
Diffstat (limited to 'brutalmaze/misc.py')
-rw-r--r-- | brutalmaze/misc.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/brutalmaze/misc.py b/brutalmaze/misc.py index eb2d45c..6593c48 100644 --- a/brutalmaze/misc.py +++ b/brutalmaze/misc.py @@ -83,13 +83,14 @@ def choices(d): if num <= w: return population[i] -def play(sound, volume, angle=None): +def play(sound, volume=1.0, angle=None): """Play a pygame.mixer.Sound at the given volume.""" if pygame.mixer.find_channel() is None: pygame.mixer.set_num_channels(pygame.mixer.get_num_channels() + 1) + + channel = sound.play() if angle is None: - sound.set_volume(volume) - sound.play() + channel.set_volume(volume) else: delta = cos(angle) volumes = [volume * (1-delta), volume * (1+delta)] @@ -98,5 +99,4 @@ def play(sound, volume, angle=None): volumes[i - 1] += v - 1 volumes[i] = 1.0 sound.set_volume(1.0) - channel = sound.play() channel.set_volume(*volumes) |