changeset 282:56cd71696dff

Use some sound files
author Neil Muller <drnlmuller@gmail.com>
date Thu, 15 Sep 2011 19:59:03 +0200
parents 2008c49b5e95
children 11cf3a259eaa
files mamba/snake.py mamba/sprites.py
diffstat 2 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/snake.py	Thu Sep 15 19:58:45 2011 +0200
+++ b/mamba/snake.py	Thu Sep 15 19:59:03 2011 +0200
@@ -7,6 +7,7 @@
 from mamba.constants import TILE_SIZE, UP, DOWN, LEFT, RIGHT
 from mamba.sprites import BaseSprite, tile_sizify
 from mamba.engine import SnakeDiedEvent, LevelCompletedEvent
+from mamba.sound import load_sound, play_sound
 from mamba import mutators
 
 
@@ -16,6 +17,7 @@
 class Snake(object):
 
     def __init__(self, tile_pos, orientation):
+        load_sound('crash', 'sounds/crash.ogg')
         self.segments = self.create_segments(tile_pos, orientation)
         self.pending_segments = []  # segments waiting to be added
         self.segment_group = Group()
@@ -109,6 +111,7 @@
             self.crash()
 
     def crash(self):
+        play_sound('crash')
         SnakeDiedEvent.post()
 
     def exit_level(self):
--- a/mamba/sprites.py	Thu Sep 15 19:58:45 2011 +0200
+++ b/mamba/sprites.py	Thu Sep 15 19:59:03 2011 +0200
@@ -4,6 +4,7 @@
 from mamba.data import load_tile_image
 from mamba.constants import TILE_SIZE, UP, DOWN, LEFT, RIGHT
 from mamba.engine import FlipArrowsEvent
+from mamba.sound import load_sound, play_sound
 from mamba import mutators
 
 
@@ -280,9 +281,18 @@
 
 
 class EdibleTile(SingleImageTileSprite):
+    sound_name = None
+
+    def __init__(self, **kw):
+        if self.sound_name:
+            load_sound(self.sound_name, self.sound_name)
+        super(EdibleTile, self).__init__(**kw)
+
     def interact(self, world, segment):
         if not segment.is_head:
             return
+        if self.sound_name:
+            play_sound(self.sound_name)
         world.snake.head.mouth_open()
         self.eat(world.snake)
         self.alive = False
@@ -294,6 +304,7 @@
 
 class BigMouse(EdibleTile):
     image_name = "rat-big"
+    sound_name = 'sounds/squeak.ogg'
 
     def eat(self, snake):
         snake.add_segment()
@@ -301,6 +312,7 @@
 
 class SmallMouse(EdibleTile):
     image_name = "rat-small"
+    sound_name = 'sounds/squeak.ogg'
 
     def eat(self, snake):
         snake.remove_segment()