From: Stefano Rivera Date: Fri, 16 May 2014 17:55:16 +0000 (+0200) Subject: Reverse beep on shutdown X-Git-Tag: 0.1~204 X-Git-Url: https://git.ctpug.org.za/?p=naja.git;a=commitdiff_plain;h=2dc5f787dbb38ebaefbe4c93a0b706c98c2574a9 Reverse beep on shutdown --- diff --git a/data/sounds/SOURCES.txt b/data/sounds/SOURCES.txt index 220eb4d..e4c8d02 100644 --- a/data/sounds/SOURCES.txt +++ b/data/sounds/SOURCES.txt @@ -41,6 +41,17 @@ Notes: License: MIT-style permissive license - see LICENSE.txt +shutdown.ogg +------------ + +Notes: + Generated by: tools/gen_sound.py 200 0.25 ; tools/gen_sound.py 400 0.25 ; tools/gen_sound.py 600 0.25 ; tools/gen_sound.py 800 0.25 ; + cat beep800.pcm beep600.pcm beep400.pcm beep200.pcm > shutdown.pcm ; + oggenc -o shutdown.ogg -r shutdown.pcm + Generated by Stefano Rivera, May 2014 + License: MIT-style permissive license - see LICENSE.txt + + zoop.ogg -------- diff --git a/data/sounds/shutdown.ogg b/data/sounds/shutdown.ogg new file mode 100644 index 0000000..c704890 Binary files /dev/null and b/data/sounds/shutdown.ogg differ diff --git a/naja/engine.py b/naja/engine.py index d7e0caf..2642feb 100644 --- a/naja/engine.py +++ b/naja/engine.py @@ -3,6 +3,7 @@ import pygame.locals as pgl from naja.constants import FPS from naja.events import SceneChangeEvent, QuitGameEvent, LoadGameEvent +from naja.sound import sound class Engine(object): @@ -36,4 +37,5 @@ class Engine(object): def quit_game(self): self._scene.exit() + sound.play_sound('shutdown.ogg', foreground=True) self._scene = None diff --git a/naja/sound.py b/naja/sound.py index 3115865..14ef8d4 100644 --- a/naja/sound.py +++ b/naja/sound.py @@ -1,5 +1,7 @@ """Sound utilities.""" +import time + from pygame import mixer from naja.options import options @@ -47,11 +49,13 @@ class PygameSound(object): sound = self._sounds[track_name] = mixer.Sound(track_name) return sound - def play_sound(self, name, volume=DEFAULT_SOUND_VOLUME): + def play_sound(self, name, volume=DEFAULT_SOUND_VOLUME, foreground=False): sound = self.load_sound(name) if sound is not None: sound.set_volume(volume) sound.play() + if foreground: + time.sleep(sound.get_length()) def play_music(self, name, volume=DEFAULT_MUSIC_VOLUME): if not options.music: