From: Neil Date: Fri, 19 Apr 2013 10:49:01 +0000 (+0200) Subject: Hook up some basic sound support X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=875fae67cf2a4f85ba9e4d785859efa28ed32691;p=erdslangetjie.git Hook up some basic sound support --- diff --git a/erdslangetjie/__main__.py b/erdslangetjie/__main__.py index dd96a96..362bded 100644 --- a/erdslangetjie/__main__.py +++ b/erdslangetjie/__main__.py @@ -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 diff --git a/erdslangetjie/data.py b/erdslangetjie/data.py index 6cca470..ad42ff3 100644 --- a/erdslangetjie/data.py +++ b/erdslangetjie/data.py @@ -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)) diff --git a/erdslangetjie/player.py b/erdslangetjie/player.py index 6f3689e..44d5a7d 100644 --- a/erdslangetjie/player.py +++ b/erdslangetjie/player.py @@ -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):