Mercurial > rinkhals
annotate gamelib/animations.py @ 380:1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sun, 25 Oct 2009 10:56:01 +0000 |
parents | a655ae452b4e |
children | 7a58dadfd251 |
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 |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
20 def __init__(self, tv, tile_pos, sequence=None, layer='animations'): |
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) |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
25 self.layer = layer |
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
26 Sprite.__init__(self, self.iter.next(), tv.tile_to_view(tile_pos)) |
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
27 tv.sprites.append(self, layer=self.layer) |
202 | 28 |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
29 def loop(self, tv, s): |
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
30 """Step to the next frame, removing sprite when done.""" |
202 | 31 try: |
32 self.setimage(self.iter.next()) | |
33 except StopIteration: | |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
34 tv.sprites.remove(self, layer=self.layer) |
202 | 35 |
36 class MuzzleFlash(Animation): | |
37 | |
235
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
38 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
|
39 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
|
40 ("right_facing",)) |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
41 |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
42 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
43 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] |
202 | 44 |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
45 def __init__(self, tv, chicken, layer='animations'): |
202 | 46 if chicken.facing == 'right': |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
47 Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_RIGHT, layer=layer) |
202 | 48 else: |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
49 Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_LEFT, layer=layer) |
202 | 50 |
241
1a7000c8211c
Demolition foxes, including better fox selection.
Jeremy Thurgood <firxen@gmail.com>
parents:
237
diff
changeset
|
51 class FenceExplosion(Animation): |
265
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
52 FLASH_1 = imagecache.load_image('sprites/boom1.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
53 FLASH_2 = imagecache.load_image('sprites/boom2.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
54 FLASH_3 = imagecache.load_image('sprites/boom3.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
55 FLASH_4 = imagecache.load_image('sprites/boom4.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
56 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
|
57 |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
58 class FoxDeath(Animation): |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
59 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
|
60 SEQUENCE = [BLOOD_SPLAT, BLOOD_SPLAT] |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
61 |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
62 class ChickenDeath(Animation): |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
63 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
|
64 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
|
65 SEQUENCE = [BLOOD_SPLAT, FEATHER_SPLAT, FEATHER_SPLAT] |