diff mamba/snake.py @ 181:061d711ba570

Interact with the world.
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 14 Sep 2011 15:27:27 +0200
parents 74f8d8cbc51d
children 0a955d2536f0
line wrap: on
line diff
--- a/mamba/snake.py	Wed Sep 14 14:08:37 2011 +0200
+++ b/mamba/snake.py	Wed Sep 14 15:27:27 2011 +0200
@@ -19,6 +19,7 @@
         self.set_orientation(orientation)
         self.speed = 120.0  # pixel / s
         self.frac_ds = 0.0
+        self.mutation = None
 
     head = property(fget=lambda self: self.segments[0])
     tail = property(fget=lambda self: self.segments[-1])
@@ -34,7 +35,7 @@
     def draw(self, surface):
         self.segment_group.draw(surface)
 
-    def update(self, dt):
+    def update(self, dt, world):
         ds = dt * self.speed + self.frac_ds
         ds, self.frac_ds = divmod(ds, 1)
         ds = int(ds)
@@ -43,6 +44,7 @@
             shifted, ds = self.head.shift_head(ds)
             if not shifted:
                 break
+            world.interact(self.head.tile_pos)
             self.head.set_orientation(self.orientation)
             for segment in self.segments[1:]:
                 old_tile_state = segment.get_tile_state()
@@ -55,6 +57,15 @@
     def set_orientation(self, orientation):
         self.orientation = orientation
 
+    def crash(self):
+        print "I'm doomed!"
+
+    def mutate(self, mutation):
+        self.mutation = mutation
+
+    def can_swim(self):
+        return self.mutation == 'amphibious'
+
 
 class Segment(BaseSprite):