202
|
1 """Animation Loops"""
|
|
2
|
|
3 from pgu.vid import Sprite
|
|
4
|
|
5 import imagecache
|
|
6 from misc import Position
|
|
7
|
|
8 class Animation(Sprite):
|
|
9 """Animation loop.
|
|
10
|
|
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
|
|
13 the sprites list.
|
|
14
|
|
15 Ideally, animations should be quite short."""
|
|
16
|
|
17 def __init__(self, sequence, tile_pos):
|
|
18 # Create the first frame
|
|
19 self.iter = iter(sequence)
|
|
20 Sprite.__init__(self, self.iter.next(), (-1000, -1000))
|
|
21 if hasattr(tile_pos, 'to_tuple'):
|
|
22 self.pos = tile_pos
|
|
23 else:
|
|
24 self.pos = Position(tile_pos[0], tile_pos[1])
|
|
25 self.removed = False
|
|
26
|
|
27 def fix_pos(self, tv):
|
|
28 ppos = tv.tile_to_view(self.pos.to_tuple())
|
|
29 self.rect.x = ppos[0]
|
|
30 self.rect.y = ppos[1]
|
|
31
|
|
32 def animate(self):
|
|
33 """Step to the next frame.
|
|
34
|
|
35 Set removed flag when we hit the end of the sequence"""
|
|
36 try:
|
|
37 self.setimage(self.iter.next())
|
|
38 except StopIteration:
|
|
39 self.removed = True
|
|
40
|
|
41 class MuzzleFlash(Animation):
|
|
42
|
|
43 SEQUENCE_LEFT = [imagecache.load_image('sprites/muzzle_flash.png')]
|
|
44 SEQUENCE_RIGHT = [imagecache.load_image('sprites/muzzle_flash.png',
|
|
45 ("right_facing",))]
|
|
46
|
|
47 def __init__(self, chicken):
|
|
48 if chicken.facing == 'right':
|
|
49 Animation.__init__(self, self.SEQUENCE_RIGHT, chicken.pos)
|
|
50 else:
|
|
51 Animation.__init__(self, self.SEQUENCE_LEFT, chicken.pos)
|
|
52
|