Mercurial > rinkhals
annotate gamelib/animations.py @ 236:9a6ac9c9ff46
chickens turn to face target foxes
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 09:46:29 +0000 |
parents | d0760fccce14 |
children | 4a87bfa5cc63 |
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 | |
235
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
45 FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png') |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
46 FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
47 ("right_facing",)) |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
48 |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
49 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
50 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] |
202 | 51 |
52 def __init__(self, chicken): | |
53 if chicken.facing == 'right': | |
54 Animation.__init__(self, self.SEQUENCE_RIGHT, chicken.pos) | |
55 else: | |
56 Animation.__init__(self, self.SEQUENCE_LEFT, chicken.pos) | |
57 |