diff mamba/sprites.py @ 282:56cd71696dff

Use some sound files
author Neil Muller <drnlmuller@gmail.com>
date Thu, 15 Sep 2011 19:59:03 +0200
parents 01c21e4f2997
children d57b7f668028
line wrap: on
line diff
--- 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()