# HG changeset patch # User Jeremy Thurgood # Date 1256470590 0 # Node ID 7a58dadfd25199b612de9b00cb5a6fbd4cdfb1a4 # Parent 1586eccdefe4d8238e951d68cd3890bcb9928d9c little cleanups, every sprite in its proper layer. diff -r 1586eccdefe4 -r 7a58dadfd251 gamelib/animations.py --- 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') diff -r 1586eccdefe4 -r 7a58dadfd251 gamelib/gameboard.py --- 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 diff -r 1586eccdefe4 -r 7a58dadfd251 gamelib/tiles.py --- 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."""