diff mamba/sprites.py @ 144:b292370c4548

Rearranged the orientation stuff. :-)
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 12 Sep 2011 21:14:15 +0200
parents 00ada2e29798
children 7fbbe27120a9
line wrap: on
line diff
--- a/mamba/sprites.py	Mon Sep 12 19:34:03 2011 -0700
+++ b/mamba/sprites.py	Mon Sep 12 21:14:15 2011 +0200
@@ -50,8 +50,8 @@
     VARIANTS = {
         '....': ('-0', ()),
 
-        'X...': ('-1', (mutators.R90,)),
-        '.X..': ('-1', (mutators.R270,)),
+        'X...': ('-1', (mutators.R270,)),
+        '.X..': ('-1', (mutators.R90,)),
         '..X.': ('-1', (mutators.NULL,)),
         '...X': ('-1', (mutators.R180,)),
 
@@ -59,8 +59,8 @@
         '..XX': ('', ()),
 
         'X.X.': ('-2a', (mutators.R180,)),
-        'X..X': ('-2a', (mutators.R270,)),
-        '.XX.': ('-2a', (mutators.R90,)),
+        'X..X': ('-2a', (mutators.R90,)),
+        '.XX.': ('-2a', (mutators.R270,)),
         '.X.X': ('-2a', (mutators.NULL,)),
 
         '.XXX': ('', ()),
@@ -72,18 +72,24 @@
         }
 
 
+class InvariantSpriteImageVariants(SpriteImageVariants):
+    def __call__(self, top, bottom, left, right):
+        return (self.base_image_name, ())
+
+
 class BaseSprite(Sprite):
     tileset = 'common'
-    variants_class = None
+    variants_class = InvariantSpriteImageVariants
     variants = None
 
     def __init__(self, tile_char=None, tileset=None, image_name=None,
-                 mutators=()):
+                 mutators=(), solid=False):
         super(BaseSprite, self).__init__()
         self.tile_char = tile_char
         if tileset is not None:
             self.tileset = tileset
         if image_name is not None:
+            self.image_name = image_name
             self.image = self.load_image(image_name, mutators=mutators)
 
     def load_image(self, image_name, mutators=()):
@@ -95,10 +101,16 @@
         self.rect = self.image.get_rect().move(tile_sizify(tile_pos))
 
     def get_variant(self, top, bottom, left, right):
-        if (self.variants_class is not None) and (self.variants is None):
+        if self.variants is None:
             self.variants = self.variants_class(self.image_name)
         return self.variants(top, bottom, left, right)
 
+    def use_variant(self, *args):
+        self.image = self.load_image(*self.get_variant(*args))
+
+    def get_solid(self, snake_mutations):
+        return self.solid
+
 
 class TileSprite(BaseSprite):
     def __init__(self, tileset, **kw):
@@ -122,6 +134,9 @@
         kw.setdefault('image_name', image_name)
         super(DoorSprite, self).__init__(**kw)
 
+    def get_solid(self, snake_mutations):
+        return self.colour in self.snake_mutations
+
 
 class EntrySprite(SingleImageTileSprite):
     image_name = 'entrance-1'