Mercurial > rinkhals
comparison 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 |
comparison
equal
deleted
inserted
replaced
379:a8a7ada27fa2 | 380:1586eccdefe4 |
---|---|
15 Ideally, animations should be quite short.""" | 15 Ideally, animations should be quite short.""" |
16 # In the current implementation, sequences longer than 4 frames | 16 # In the current implementation, sequences longer than 4 frames |
17 # will cause issues as this will overrun the next move loop. | 17 # will cause issues as this will overrun the next move loop. |
18 # (assuming all animations are triggered by the move loop, of course) | 18 # (assuming all animations are triggered by the move loop, of course) |
19 | 19 |
20 def __init__(self, tile_pos, sequence=None): | 20 def __init__(self, tv, tile_pos, sequence=None, layer='animations'): |
21 # Create the first frame | 21 # Create the first frame |
22 if sequence is None: | 22 if sequence is None: |
23 sequence = self.SEQUENCE | 23 sequence = self.SEQUENCE |
24 self.iter = iter(sequence) | 24 self.iter = iter(sequence) |
25 Sprite.__init__(self, self.iter.next(), (-1000, -1000)) | 25 self.layer = layer |
26 if hasattr(tile_pos, 'to_tuple'): | 26 Sprite.__init__(self, self.iter.next(), tv.tile_to_view(tile_pos)) |
27 self.pos = tile_pos | 27 tv.sprites.append(self, layer=self.layer) |
28 else: | |
29 self.pos = Position(tile_pos[0], tile_pos[1]) | |
30 self.removed = False | |
31 | 28 |
32 def fix_pos(self, tv): | 29 def loop(self, tv, s): |
33 ppos = tv.tile_to_view(self.pos.to_tuple()) | 30 """Step to the next frame, removing sprite when done.""" |
34 self.rect.x = ppos[0] | |
35 self.rect.y = ppos[1] | |
36 | |
37 def animate(self): | |
38 """Step to the next frame. | |
39 | |
40 Set removed flag when we hit the end of the sequence""" | |
41 try: | 31 try: |
42 self.setimage(self.iter.next()) | 32 self.setimage(self.iter.next()) |
43 except StopIteration: | 33 except StopIteration: |
44 self.removed = True | 34 tv.sprites.remove(self, layer=self.layer) |
45 | 35 |
46 class MuzzleFlash(Animation): | 36 class MuzzleFlash(Animation): |
47 | 37 |
48 FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png') | 38 FLASH_LEFT = imagecache.load_image('sprites/muzzle_flash.png') |
49 FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', | 39 FLASH_RIGHT = imagecache.load_image('sprites/muzzle_flash.png', |
50 ("right_facing",)) | 40 ("right_facing",)) |
51 | 41 |
52 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] | 42 SEQUENCE_LEFT = [FLASH_LEFT, FLASH_LEFT] |
53 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] | 43 SEQUENCE_RIGHT = [FLASH_RIGHT, FLASH_RIGHT] |
54 | 44 |
55 def __init__(self, chicken): | 45 def __init__(self, tv, chicken, layer='animations'): |
56 if chicken.facing == 'right': | 46 if chicken.facing == 'right': |
57 Animation.__init__(self, chicken.pos, self.SEQUENCE_RIGHT) | 47 Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_RIGHT, layer=layer) |
58 else: | 48 else: |
59 Animation.__init__(self, chicken.pos, self.SEQUENCE_LEFT) | 49 Animation.__init__(self, tv, chicken.pos.to_tuple(), self.SEQUENCE_LEFT, layer=layer) |
60 | 50 |
61 class FenceExplosion(Animation): | 51 class FenceExplosion(Animation): |
62 FLASH_1 = imagecache.load_image('sprites/boom1.png') | 52 FLASH_1 = imagecache.load_image('sprites/boom1.png') |
63 FLASH_2 = imagecache.load_image('sprites/boom2.png') | 53 FLASH_2 = imagecache.load_image('sprites/boom2.png') |
64 FLASH_3 = imagecache.load_image('sprites/boom3.png') | 54 FLASH_3 = imagecache.load_image('sprites/boom3.png') |