Mercurial > rinkhals
annotate gamelib/animations.py @ 234:ee1ac134022d
Fix drawing bug with multiframe animations
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 09:23:11 +0000 |
parents | d3d5352f5853 |
children | d0760fccce14 |
rev | line source |
---|---|
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.""" | |
233
d3d5352f5853
Twek speed loop. Document animation assumptions
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
16 # In the current implementation, sequences longer than 3 frames |
d3d5352f5853
Twek speed loop. Document animation assumptions
Neil Muller <drnlmuller@gmail.com>
parents:
202
diff
changeset
|
17 # will cause issues as this will overrun the next move loop. |
202 | 18 |
19 def __init__(self, sequence, tile_pos): | |
20 # Create the first frame | |
21 self.iter = iter(sequence) | |
22 Sprite.__init__(self, self.iter.next(), (-1000, -1000)) | |
23 if hasattr(tile_pos, 'to_tuple'): | |
24 self.pos = tile_pos | |
25 else: | |
26 self.pos = Position(tile_pos[0], tile_pos[1]) | |
27 self.removed = False | |
28 | |
29 def fix_pos(self, tv): | |
30 ppos = tv.tile_to_view(self.pos.to_tuple()) | |
31 self.rect.x = ppos[0] | |
32 self.rect.y = ppos[1] | |
33 | |
34 def animate(self): | |
35 """Step to the next frame. | |
36 | |
37 Set removed flag when we hit the end of the sequence""" | |
38 try: | |
39 self.setimage(self.iter.next()) | |
40 except StopIteration: | |
41 self.removed = True | |
42 | |
43 class MuzzleFlash(Animation): | |
44 | |
45 SEQUENCE_LEFT = [imagecache.load_image('sprites/muzzle_flash.png')] | |
46 SEQUENCE_RIGHT = [imagecache.load_image('sprites/muzzle_flash.png', | |
47 ("right_facing",))] | |
48 | |
49 def __init__(self, chicken): | |
50 if chicken.facing == 'right': | |
51 Animation.__init__(self, self.SEQUENCE_RIGHT, chicken.pos) | |
52 else: | |
53 Animation.__init__(self, self.SEQUENCE_LEFT, chicken.pos) | |
54 |