Mercurial > rinkhals
annotate gamelib/animations.py @ 349:a36ab7dd0eb9
Fix 'Are You Sure?' dialog to work at night
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 05 Sep 2009 23:18:27 +0000 |
parents | a655ae452b4e |
children | 1586eccdefe4 |
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.""" | |
237 | 16 # In the current implementation, sequences longer than 4 frames |
233
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. |
237 | 18 # (assuming all animations are triggered by the move loop, of course) |
202 | 19 |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
20 def __init__(self, tile_pos, sequence=None): |
202 | 21 # Create the first frame |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
22 if sequence is None: |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
23 sequence = self.SEQUENCE |
202 | 24 self.iter = iter(sequence) |
25 Sprite.__init__(self, self.iter.next(), (-1000, -1000)) | |
26 if hasattr(tile_pos, 'to_tuple'): | |
27 self.pos = tile_pos | |
28 else: | |
29 self.pos = Position(tile_pos[0], tile_pos[1]) | |
30 self.removed = False | |
31 | |
32 def fix_pos(self, tv): | |
33 ppos = tv.tile_to_view(self.pos.to_tuple()) | |
34 self.rect.x = ppos[0] | |
35 self.rect.y = ppos[1] | |
36 | |
37 def animate(self): | |
38 """Step to the next frame. | |
39 | |
40 Set removed flag when we hit the end of the sequence""" | |
41 try: | |
42 self.setimage(self.iter.next()) | |
43 except StopIteration: | |
44 self.removed = True | |
45 | |
46 class MuzzleFlash(Animation): | |
47 | |
235
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
48 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
|
49 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
|
50 ("right_facing",)) |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
51 |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
52 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
53 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] |
202 | 54 |
55 def __init__(self, chicken): | |
56 if chicken.facing == 'right': | |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
57 Animation.__init__(self, chicken.pos, self.SEQUENCE_RIGHT) |
202 | 58 else: |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
59 Animation.__init__(self, chicken.pos, self.SEQUENCE_LEFT) |
202 | 60 |
241
1a7000c8211c
Demolition foxes, including better fox selection.
Jeremy Thurgood <firxen@gmail.com>
parents:
237
diff
changeset
|
61 class FenceExplosion(Animation): |
265
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
62 FLASH_1 = imagecache.load_image('sprites/boom1.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
63 FLASH_2 = imagecache.load_image('sprites/boom2.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
64 FLASH_3 = imagecache.load_image('sprites/boom3.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
65 FLASH_4 = imagecache.load_image('sprites/boom4.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
66 SEQUENCE = [FLASH_1, FLASH_2, FLASH_3, FLASH_4] |
241
1a7000c8211c
Demolition foxes, including better fox selection.
Jeremy Thurgood <firxen@gmail.com>
parents:
237
diff
changeset
|
67 |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
68 class FoxDeath(Animation): |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
69 BLOOD_SPLAT = imagecache.load_image('sprites/fox_death.png') |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
70 SEQUENCE = [BLOOD_SPLAT, BLOOD_SPLAT] |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
71 |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
72 class ChickenDeath(Animation): |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
73 BLOOD_SPLAT = imagecache.load_image('sprites/fox_death.png') |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
74 FEATHER_SPLAT = imagecache.load_image('sprites/chkn_death.png') |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
75 SEQUENCE = [BLOOD_SPLAT, FEATHER_SPLAT, FEATHER_SPLAT] |