Mercurial > rinkhals
annotate gamelib/animations.py @ 404:e5247ec76f24
The new faster deciding (but somewhat dumber) fox
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 19 Nov 2009 13:33:57 +0000 |
parents | 2d0ff46118e2 |
children | e65536ca215b |
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 | |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
12 respects. Ideally, animations should be quite short.""" |
237 | 13 # In the current implementation, sequences longer than 4 frames |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
14 # will overrun the next move loop. |
237 | 15 # (assuming all animations are triggered by the move loop, of course) |
202 | 16 |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
17 def __init__(self, tv, tile_pos, sequence=None, layer='animations'): |
202 | 18 # Create the first frame |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
19 if sequence is None: |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
20 sequence = self.SEQUENCE |
202 | 21 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
|
22 self.layer = layer |
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
23 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
|
24 tv.sprites.append(self, layer=self.layer) |
202 | 25 |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
26 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
|
27 """Step to the next frame, removing sprite when done.""" |
202 | 28 try: |
29 self.setimage(self.iter.next()) | |
30 except StopIteration: | |
380
1586eccdefe4
Ripped out legacy animation infrastructure in favour of layered sprites.
Jeremy Thurgood <firxen@gmail.com>
parents:
265
diff
changeset
|
31 tv.sprites.remove(self, layer=self.layer) |
202 | 32 |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
33 class WeaponAnimation(Animation): |
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
34 def __init__(self, tv, wielder, layer='animations'): |
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
35 if wielder.facing == 'right': |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
381
diff
changeset
|
36 Animation.__init__(self, tv, wielder.pos.to_tile_tuple(), self.SEQUENCE_RIGHT, layer=layer) |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
37 else: |
395
2d0ff46118e2
Basic support for z coordinate
Neil Muller <drnlmuller@gmail.com>
parents:
381
diff
changeset
|
38 Animation.__init__(self, tv, wielder.pos.to_tile_tuple(), self.SEQUENCE_LEFT, layer=layer) |
202 | 39 |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
40 |
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
41 class MuzzleFlash(WeaponAnimation): |
235
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
42 FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png') |
381
7a58dadfd251
little cleanups, every sprite in its proper layer.
Jeremy Thurgood <firxen@gmail.com>
parents:
380
diff
changeset
|
43 FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', ("right_facing",)) |
235
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
44 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] |
d0760fccce14
Hold flash for a bit longer
Neil Muller <drnlmuller@gmail.com>
parents:
233
diff
changeset
|
45 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] |
202 | 46 |
241
1a7000c8211c
Demolition foxes, including better fox selection.
Jeremy Thurgood <firxen@gmail.com>
parents:
237
diff
changeset
|
47 class FenceExplosion(Animation): |
265
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
48 FLASH_1 = imagecache.load_image('sprites/boom1.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
49 FLASH_2 = imagecache.load_image('sprites/boom2.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
50 FLASH_3 = imagecache.load_image('sprites/boom3.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
51 FLASH_4 = imagecache.load_image('sprites/boom4.png') |
a655ae452b4e
updated fence explosion animation
Adrianna Pińska <adrianna.pinska@gmail.com>
parents:
251
diff
changeset
|
52 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
|
53 |
251
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
54 class FoxDeath(Animation): |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
55 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
|
56 SEQUENCE = [BLOOD_SPLAT, BLOOD_SPLAT] |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
57 |
844bfb23d4b6
Refactored animal death and added death animations.
Jeremy Thurgood <firxen@gmail.com>
parents:
241
diff
changeset
|
58 class ChickenDeath(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 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
|
61 SEQUENCE = [BLOOD_SPLAT, FEATHER_SPLAT, FEATHER_SPLAT] |