annotate gamelib/animations.py @ 265:a655ae452b4e

updated fence explosion animation
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Sat, 05 Sep 2009 13:57:17 +0000
parents 844bfb23d4b6
children 1586eccdefe4
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 from misc import Position
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
7
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
8 class Animation(Sprite):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
9 """Animation loop.
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
10
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
11 These are derived from sprites, since they behave similiary in most
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
12 respects, but, to ensure draw ordering, we don't add them to
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
13 the sprites list.
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
14
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
15 Ideally, animations should be quite short."""
237
4a87bfa5cc63 Twiddle animation cycle
Neil Muller <drnlmuller@gmail.com>
parents: 235
diff changeset
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
4a87bfa5cc63 Twiddle animation cycle
Neil Muller <drnlmuller@gmail.com>
parents: 235
diff changeset
18 # (assuming all animations are triggered by the move loop, of course)
202
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
24 self.iter = iter(sequence)
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
25 Sprite.__init__(self, self.iter.next(), (-1000, -1000))
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
26 if hasattr(tile_pos, 'to_tuple'):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
27 self.pos = tile_pos
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
28 else:
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
29 self.pos = Position(tile_pos[0], tile_pos[1])
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
30 self.removed = False
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
31
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
32 def fix_pos(self, tv):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
33 ppos = tv.tile_to_view(self.pos.to_tuple())
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
34 self.rect.x = ppos[0]
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
35 self.rect.y = ppos[1]
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
36
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
37 def animate(self):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
38 """Step to the next frame.
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
39
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
40 Set removed flag when we hit the end of the sequence"""
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
41 try:
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
42 self.setimage(self.iter.next())
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
43 except StopIteration:
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
44 self.removed = True
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
45
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
46 class MuzzleFlash(Animation):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
54
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
55 def __init__(self, chicken):
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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
3074784c93f4 Animation support
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
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]