changeset 419:add81f2b747e

Boomslang!
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 28 Aug 2010 23:01:30 +0200
parents 6a24970a0d21
children f173771c85a8
files gamelib/scenes/mess.py
diffstat 1 files changed, 44 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/mess.py	Sat Aug 28 22:57:05 2010 +0200
+++ b/gamelib/scenes/mess.py	Sat Aug 28 23:01:30 2010 +0200
@@ -1,6 +1,6 @@
 """Mess where crew eat. Fun stuff."""
 
-from random import choice
+from random import choice, randint
 
 from gamelib.state import Scene, Item, CloneableItem, Thing, Result
 from gamelib.cursor import CursorSprite
@@ -9,6 +9,9 @@
                                           InteractImageRect, InteractAnimated,
                                           GenericDescThing)
 
+from gamelib.sound import get_sound
+from gamelib import constants
+
 
 class Mess(Scene):
 
@@ -26,6 +29,7 @@
         self.add_thing(Tubes())
         self.add_thing(ToMap())
         self.add_thing(DetergentThing())
+        self.add_thing(Boomslang())
         self.add_item(DetergentBottle('detergent_bottle'))
         # Flavour items
         # extra cans on shelf
@@ -213,6 +217,45 @@
                           " tape could actually be used to tape ducts?")
 
 
+class Boomslang(Thing):
+    NAME = 'mess.boomslang'
+
+    INTERACTS = {
+        'snake': InteractAnimated(455, 241, (
+            'boomslang_no_tongue.png', 'boomslang_with_tongue.png',
+            'boomslang_no_tongue.png', 'boomslang_with_tongue.png',
+            'boomslang_no_tongue.png',
+            ), 5),
+        'no_snake': InteractNoImage(0, 0, 0, 0),
+    }
+
+    INITIAL = 'no_snake'
+
+    INITIAL_DATA = {
+        'anim_pos': -1,
+        }
+
+    HISS = get_sound('boomslang.ogg')
+
+    def is_interactive(self):
+        return False
+
+    def animate(self):
+        if self.get_data('anim_pos') > -1:
+            self.current_interact.animate()
+            if self.get_data('anim_pos') > self.current_interact._anim_pos:
+                self.set_interact('no_snake')
+                self.set_data('anim_pos', -1)
+            else:
+                self.set_data('anim_pos', self.current_interact._anim_pos)
+            return True
+        if randint(0, 30 * constants.FRAME_RATE) == 0:
+            self.set_interact('snake')
+            self.set_data('anim_pos', 0)
+            self.HISS.play()
+        return False
+
+
 class DetergentThing(Thing):
 
     NAME = "mess.detergent"