changeset 381:7a58dadfd251

little cleanups, every sprite in its proper layer.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 25 Oct 2009 11:36:30 +0000
parents 1586eccdefe4
children e89e6ad011ac
files gamelib/animations.py gamelib/gameboard.py gamelib/tiles.py
diffstat 3 files changed, 14 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animations.py	Sun Oct 25 10:56:01 2009 +0000
+++ b/gamelib/animations.py	Sun Oct 25 11:36:30 2009 +0000
@@ -9,12 +9,9 @@
     """Animation loop.
 
        These are derived from sprites, since they behave similiary in most
-       respects, but, to ensure draw ordering, we don't add them to
-       the sprites list.
-       
-       Ideally, animations should be quite short."""
+       respects. Ideally, animations should be quite short."""
        # In the current implementation, sequences longer than 4 frames
-       # will cause issues as this will overrun the next move loop.
+       # will overrun the next move loop.
        # (assuming all animations are triggered by the move loop, of course)
 
     def __init__(self, tv, tile_pos, sequence=None, layer='animations'):
@@ -33,21 +30,20 @@
         except StopIteration:
             tv.sprites.remove(self, layer=self.layer)
 
-class MuzzleFlash(Animation):
+class WeaponAnimation(Animation):
+    def __init__(self, tv, wielder, layer='animations'):
+        if wielder.facing == 'right':
+            Animation.__init__(self, tv, wielder.pos.to_tuple(), self.SEQUENCE_RIGHT, layer=layer)
+        else:
+            Animation.__init__(self, tv, wielder.pos.to_tuple(), self.SEQUENCE_LEFT, layer=layer)
 
+
+class MuzzleFlash(WeaponAnimation):
     FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png')
-    FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png',
-            ("right_facing",))
-
+    FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', ("right_facing",))
     SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT]
     SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT]
 
-    def __init__(self, tv, chicken, layer='animations'):
-        if chicken.facing == 'right':
-            Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_RIGHT, layer=layer)
-        else:
-            Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_LEFT, layer=layer)
-
 class FenceExplosion(Animation):
     FLASH_1 = imagecache.load_image('sprites/boom1.png')
     FLASH_2 = imagecache.load_image('sprites/boom2.png')
--- a/gamelib/gameboard.py	Sun Oct 25 10:56:01 2009 +0000
+++ b/gamelib/gameboard.py	Sun Oct 25 11:36:30 2009 +0000
@@ -822,7 +822,7 @@
 
     def add_building(self, building):
         self.buildings.append(building)
-        self.tv.sprites.append(building)
+        self.tv.sprites.append(building, layer='buildings')
 
     def lay_eggs(self):
         self.eggs = 0
@@ -883,7 +883,7 @@
     def remove_building(self, building):
         if building in self.buildings:
             self.buildings.remove(building)
-            self.tv.sprites.remove(building)
+            self.tv.sprites.remove(building, layer='buildings')
 
     def add_cash(self, amount):
         self.cash += amount
--- a/gamelib/tiles.py	Sun Oct 25 10:56:01 2009 +0000
+++ b/gamelib/tiles.py	Sun Oct 25 11:36:30 2009 +0000
@@ -94,7 +94,7 @@
        """
     def __init__(self):
         tilevid.Tilevid.__init__(self)
-        self.sprites = LayeredSprites(['animals', 'buildings', 'animations', 'cursor'], 'animals')
+        self.sprites = LayeredSprites(['buildings', 'animals', 'animations', 'cursor'], 'animals')
 
     def png_folder_load_tiles(self, path):
         """Load tiles from a folder of PNG files."""