Hook up some basic sound support
authorNeil <neil@dip.sun.ac.za>
Fri, 19 Apr 2013 10:49:01 +0000 (12:49 +0200)
committerNeil <neil@dip.sun.ac.za>
Fri, 19 Apr 2013 10:49:01 +0000 (12:49 +0200)
erdslangetjie/__main__.py
erdslangetjie/data.py
erdslangetjie/player.py

index dd96a96be8e6d983319d46de1662234e77aa0460..362bded7dd84ffe240d2982c8e2ce918f839d0cd 100644 (file)
@@ -12,7 +12,7 @@ from kivy.clock import Clock
 from kivy.config import Config
 
 from erdslangetjie.level import LevelList
-from erdslangetjie.data import load_image
+from erdslangetjie.data import load_image, load_sound
 from erdslangetjie.player import ThePlayer, Nemesis
 
 
@@ -42,8 +42,10 @@ class GameWindow(RelativeLayout):
 
         self.mouse_move = False
 
+        self.caught = load_sound('sounds/caught.ogg')
+
         self.player = ThePlayer()
-        self.nemesis = Nemesis()
+        self.nemesis = Nemesis(self.app.config)
         if not self.level_obj.enter_pos:
             raise RuntimeError('No entry point')
         self.player_tile = None
@@ -248,6 +250,8 @@ class GameWindow(RelativeLayout):
             return
         elif self.check_caught():
             # Caught
+            if self.app.config.getdefault('bane', 'sound', '0') != '0':
+                self.caught.play()
             self.reset_level()
             app = self.app
             self.app = None
index 6cca470f4f926b04ea0e84cb727df843cc585b2d..ad42ff3f58e8b25920583922c3a3431427cd5c3c 100644 (file)
@@ -10,10 +10,12 @@ pyglet.resource search path.
 
 import os
 from kivy.core.image import ImageLoader
+from kivy.core.audio import SoundLoader
 
 data_py = os.path.abspath(os.path.dirname(__file__))
 data_dir = os.path.normpath(os.path.join(data_py, '..', 'data'))
 loader = ImageLoader()
+soundloader = SoundLoader()
 
 
 def filepath(filename):
@@ -35,3 +37,7 @@ def load_image(filename):
     '''Load an image into a kivy texture. We rely on kivy's caching
        infrastructure'''
     return loader.load(filepath(filename))
+
+
+def load_sound(filename):
+    return soundloader.load(filepath(filename))
index 6f3689e39cae0a3e919396c6950ad52f4032b9cb..44d5a7dba9e0a60cd2e549028e61ca988c12d8fb 100644 (file)
@@ -1,6 +1,5 @@
 # Player and Player-like objects
-
-from erdslangetjie.data import load_image
+from erdslangetjie.data import load_image, load_sound
 
 
 class GameSprite(object):
@@ -39,12 +38,14 @@ class ThePlayer(FigureSprite):
 
 class Nemesis(FigureSprite):
 
-    def __init__(self):
+    def __init__(self, config):
         super(Nemesis, self).__init__()
         self.sprite = load_image('sprites/nemesis.png')
         self.reset_pos()
+        self._config = config
         self._deadends = set([])
         self._been = {}
+        self._bend = load_sound('sounds/bend.ogg')
 
     def move(self, level, player_pos):
         if not self.on_board():
@@ -62,6 +63,8 @@ class Nemesis(FigureSprite):
         for cand in neighbours:
             if level.is_gate(cand) and level.blocked(cand):
                 level.damage_gate(cand)
+                if self._config.getdefault('bane', 'sound', False):
+                    self._bend.play()
                 return
         # check for dead-ends
         if self._in_dead_end(level):