diff --git a/README b/README index d7d9751..91c0774 100644 --- a/README +++ b/README @@ -32,7 +32,7 @@ class SampleGame(Game): if __name__ == '__main__': - SampleGame().play() + SampleGame().run() License diff --git a/pgfw/Audio.py b/pgfw/Audio.py index 8e2bcbd..77c497b 100644 --- a/pgfw/Audio.py +++ b/pgfw/Audio.py @@ -48,3 +48,27 @@ class Audio(GameChild): if sound not in self.original_volumes.keys(): self.original_volumes[sound] = sound.get_volume() sound.set_volume(self.original_volumes[sound] * self.volume) + + +class SoundEffect(GameChild, Sound): + + def __init__(self, parent, path, volume=1.0): + GameChild.__init__(self, parent) + Sound.__init__(self, path) + self.display_surface = self.get_display_surface() + self.initial_volume = volume + self.set_volume(volume) + + def play(self, loops=0, maxtime=0, fade_ms=0, position=None, x=None): + self.set_volume(self.initial_volume * + self.get_configuration("audio", "sfx-volume")) + channel = Sound.play(self, loops, maxtime, fade_ms) + if x is not None: + position = float(x) / self.display_surface.get_width() + if position is not None and channel is not None: + channel.set_volume(*self.get_panning(position)) + return channel + + def get_panning(self, position): + return 1 - max(0, ((position - .5) * 2)), \ + 1 + min(0, ((position - .5) * 2)) diff --git a/sample.py b/sample.py index 44e3a02..e22d237 100644 --- a/sample.py +++ b/sample.py @@ -21,4 +21,4 @@ class SampleGame(Game): if __name__ == '__main__': # the play method begins the project's animation - SampleGame().play() + SampleGame().run()