comparison gamelib/animations.py @ 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 2d0ff46118e2
comparison
equal deleted inserted replaced
380:1586eccdefe4 381:7a58dadfd251
7 7
8 class Animation(Sprite): 8 class Animation(Sprite):
9 """Animation loop. 9 """Animation loop.
10 10
11 These are derived from sprites, since they behave similiary in most 11 These are derived from sprites, since they behave similiary in most
12 respects, but, to ensure draw ordering, we don't add them to 12 respects. Ideally, animations should be quite short."""
13 the sprites list.
14
15 Ideally, animations should be quite short."""
16 # In the current implementation, sequences longer than 4 frames 13 # In the current implementation, sequences longer than 4 frames
17 # will cause issues as this will overrun the next move loop. 14 # will overrun the next move loop.
18 # (assuming all animations are triggered by the move loop, of course) 15 # (assuming all animations are triggered by the move loop, of course)
19 16
20 def __init__(self, tv, tile_pos, sequence=None, layer='animations'): 17 def __init__(self, tv, tile_pos, sequence=None, layer='animations'):
21 # Create the first frame 18 # Create the first frame
22 if sequence is None: 19 if sequence is None:
31 try: 28 try:
32 self.setimage(self.iter.next()) 29 self.setimage(self.iter.next())
33 except StopIteration: 30 except StopIteration:
34 tv.sprites.remove(self, layer=self.layer) 31 tv.sprites.remove(self, layer=self.layer)
35 32
36 class MuzzleFlash(Animation): 33 class WeaponAnimation(Animation):
34 def __init__(self, tv, wielder, layer='animations'):
35 if wielder.facing == 'right':
36 Animation.__init__(self, tv, wielder.pos.to_tuple(), self.SEQUENCE_RIGHT, layer=layer)
37 else:
38 Animation.__init__(self, tv, wielder.pos.to_tuple(), self.SEQUENCE_LEFT, layer=layer)
37 39
40
41 class MuzzleFlash(WeaponAnimation):
38 FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png') 42 FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png')
39 FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', 43 FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', ("right_facing",))
40 ("right_facing",))
41
42 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] 44 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT]
43 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] 45 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT]
44
45 def __init__(self, tv, chicken, layer='animations'):
46 if chicken.facing == 'right':
47 Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_RIGHT, layer=layer)
48 else:
49 Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_LEFT, layer=layer)
50 46
51 class FenceExplosion(Animation): 47 class FenceExplosion(Animation):
52 FLASH_1 = imagecache.load_image('sprites/boom1.png') 48 FLASH_1 = imagecache.load_image('sprites/boom1.png')
53 FLASH_2 = imagecache.load_image('sprites/boom2.png') 49 FLASH_2 = imagecache.load_image('sprites/boom2.png')
54 FLASH_3 = imagecache.load_image('sprites/boom3.png') 50 FLASH_3 = imagecache.load_image('sprites/boom3.png')