annotate gamelib/animations.py @ 600:f9276a4f7bdf

rooster sprite
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Thu, 03 Dec 2009 19:29:54 +0000
parents e65536ca215b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
202
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
1 """Animation Loops"""
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
2
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
3 from pgu.vid import Sprite
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
4
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
5 import imagecache
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
6
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
7 class Animation(Sprite):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
8 """Animation loop.
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
9
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
4a87bfa5cc63 Twiddle animation cycle
Neil Muller <drnlmuller@gmail.com>
parents: 235
diff changeset
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
4a87bfa5cc63 Twiddle animation cycle
Neil Muller <drnlmuller@gmail.com>
parents: 235
diff changeset
14 # (assuming all animations are triggered by the move loop, of course)
202
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
27 try:
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
28 self.setimage(self.iter.next())
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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]