Reverse beep on shutdown
authorStefano Rivera <stefano@rivera.za.net>
Fri, 16 May 2014 17:55:16 +0000 (19:55 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Fri, 16 May 2014 17:55:16 +0000 (19:55 +0200)
data/sounds/SOURCES.txt
data/sounds/shutdown.ogg [new file with mode: 0644]
naja/engine.py
naja/sound.py

index 220eb4d4eee2ca9f5172aa812254e746a27c4216..e4c8d023f6fdf899ef23ff01f8f5875bb9f48585 100644 (file)
@@ -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 (file)
index 0000000..c704890
Binary files /dev/null and b/data/sounds/shutdown.ogg differ
index d7e0caf62539de966abae6746adc66bb9ad7f4ff..2642feb3481de6407b63ebb02cd58b0a3691afd2 100644 (file)
@@ -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
index 311586510874fd792241b3c72455b736f3b0af46..14ef8d4bac9bc56ff79aa88030ae3d3404691924 100644 (file)
@@ -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: