changeset 131:513037749086

eye
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Sun, 11 Sep 2011 22:28:13 +0200
parents 9bef49d6db86
children 0abd6e3680b6
files mamba/mutators.py mamba/snake.py
diffstat 2 files changed, 26 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/mutators.py	Sun Sep 11 22:19:59 2011 +0200
+++ b/mamba/mutators.py	Sun Sep 11 22:28:13 2011 +0200
@@ -21,6 +21,9 @@
     def __eq__(self, other):
         return (self._func is other.func) and self._args == other._args
 
+    def __repr__(self):
+        return "<%s args=%r>" % (self.__class__.__name__, self._args)
+
 
 # mutator that does nothing
 NULL = Mutator(lambda x: x)
@@ -44,11 +47,7 @@
 class Overlay(Mutator):
     """Overlay another image on top of the given one."""
 
-    BLEND = BLEND_ADD
-
-    def __init__(self, filename, blend=None):
-        if blend is None:
-            blend = self.BLEND
+    def __init__(self, filename, blend=0):
         super(Overlay, self).__init__(self.overlay, filename, blend)
 
     def overlay(self, image, filename, blend):
--- a/mamba/snake.py	Sun Sep 11 22:19:59 2011 +0200
+++ b/mamba/snake.py	Sun Sep 11 22:28:13 2011 +0200
@@ -57,16 +57,19 @@
     RED = mutators.RED
     YELLOW = mutators.YELLOW
 
+    _detail_mutators = ()
+
     def __init__(self, image_name, tile_pos):
         super(Segment, self).__init__()
         self._base_image = "/".join(["snake", image_name])
+        self._colour_overlay = self.GREEN
         self._orientation = Snake.UP
 
-        self.make_images(self.GREEN)
+        self.make_images()
         self.update_image()
         self.set_tile_pos(tile_pos)
 
-    def make_images(self, colour_overlay):
+    def make_images(self):
         self._images = {}
         for orientation, muts in [
             (Snake.RIGHT, (mutators.RIGHT,)),
@@ -74,7 +77,8 @@
             (Snake.UP, (mutators.UP,)),
             (Snake.DOWN, (mutators.DOWN,)),
             ]:
-            self._images[orientation] = self.load_image(self._base_image, muts + (colour_overlay,))
+            all_muts = (self._colour_overlay,) + self._detail_mutators + muts
+            self._images[orientation] = self.load_image(self._base_image, all_muts)
 
     def update_image(self):
         self.image = self._images[self._orientation]
@@ -84,14 +88,28 @@
         self.update_image()
 
     def set_colour(self, colour_overlay):
-        self.make_images(colour_overlay)
+        self._colour_overlay = colour_overlay
+        self.make_images()
         self.update_image()
 
 
 class Head(Segment):
     def __init__(self, tile_pos):
+        self._eye = mutators.Overlay("tiles/common/snake/snake-head-eye-r.png")
+        self._tongue = mutators.Overlay("tiles/common/snake/snake-head-tongue-r.png")
+        self._detail_mutators = (self._eye,)
         super(Head, self).__init__("snake-head-mouth-open-r", tile_pos)
 
+    def tongue_out(self):
+        self._detail_mutators = (self._eye, self._tongue)
+        self.make_images()
+        self.update_image()
+
+    def tongue_in(self):
+        self._detail_mutators = (self._eye,)
+        self.make_images()
+        self.update_image()
+
 
 class Body(Segment):
     def __init__(self, tile_pos):