changeset 125:625b22f92efa

the snake is green
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Sun, 11 Sep 2011 21:35:39 +0200
parents d285cf18396e
children 666a0760241e
files mamba/data.py mamba/mutators.py mamba/snake.py
diffstat 3 files changed, 30 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mamba/data.py	Sun Sep 11 21:34:07 2011 -0700
+++ b/mamba/data.py	Sun Sep 11 21:35:39 2011 +0200
@@ -37,6 +37,7 @@
 
 
 def load_image(filename, mutators=()):
+    print "+++++++++++", filename
     key = (filename, mutators)
     if key in MUTATED_IMAGES:
         return MUTATED_IMAGES[key]
--- a/mamba/mutators.py	Sun Sep 11 21:34:07 2011 -0700
+++ b/mamba/mutators.py	Sun Sep 11 21:35:39 2011 +0200
@@ -47,16 +47,16 @@
     def __init__(self, filename, blend=None):
         if blend is None:
             blend = self.BLEND
-        super(Overlay, self).__init__(self.overlay, blend, filename)
+        super(Overlay, self).__init__(self.overlay, filename, blend)
 
     def overlay(self, image, filename, blend):
         image = image.copy()
         overlay = load_image(filename)
-        overlay.blit(image, None, blend)
+        image.blit(overlay, (0, 0), None, blend)
         return image
 
 
 # colours
-BLUE = Overlay("data/tiles/common/blue.png", BLEND_MULT)
-RED = Overlay("data/tiles/common/red.png", BLEND_MULT)
-YELLOW = Overlay("data/tiles/common/yellow.png", BLEND_MULT)
+BLUE = Overlay("tiles/common/blue.png", BLEND_MULT)
+RED = Overlay("tiles/common/red.png", BLEND_MULT)
+YELLOW = Overlay("tiles/common/yellow.png", BLEND_MULT)
--- a/mamba/snake.py	Sun Sep 11 21:34:07 2011 -0700
+++ b/mamba/snake.py	Sun Sep 11 21:35:39 2011 +0200
@@ -1,6 +1,7 @@
 """The player snake object."""
 
 from pygame.sprite import Group
+from pygame.locals import BLEND_MULT
 
 from mamba.sprites import BaseSprite
 from mamba import mutators
@@ -43,9 +44,21 @@
 
 class Segment(BaseSprite):
 
+    GREEN = mutators.Overlay("tiles/common/snake/green.png", BLEND_MULT)
+    BLUE = mutators.BLUE
+    RED = mutators.RED
+    YELLOW = mutators.YELLOW
+
     def __init__(self, image_name, tile_pos):
         super(Segment, self).__init__()
-        image_name = "/".join(["snake", image_name])
+        self._base_image = "/".join(["snake", image_name])
+        self._orientation = Snake.UP
+
+        self.make_images(self.GREEN)
+        self.update_image()
+        self.set_tile_pos(tile_pos)
+
+    def make_images(self, colour_overlay):
         self._images = {}
         for orientation, muts in [
             (Snake.RIGHT, (mutators.RIGHT,)),
@@ -53,12 +66,18 @@
             (Snake.UP, (mutators.UP,)),
             (Snake.DOWN, (mutators.DOWN,)),
             ]:
-            self._images[orientation] = self.load_image(image_name, muts)
-        self.set_orientation(Snake.UP)
-        self.set_tile_pos(tile_pos)
+            self._images[orientation] = self.load_image(self._base_image, muts + (colour_overlay,))
+
+    def update_image(self):
+        self.image = self._images[self._orientation]
 
     def set_orientation(self, orientation):
-        self.image = self._images[orientation]
+        self._orientation = orientation
+        self.update_image()
+
+    def set_colour(self, colour_overlay):
+        self.make_images(colour_overlay)
+        self.update_image()
 
 
 class Head(Segment):