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