Mercurial > skaapsteker
comparison skaapsteker/sprites/player.py @ 120:9b08afeadf06
Animated running.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Mon, 04 Apr 2011 22:11:33 +0200 |
parents | 69a97094417a |
children | 51bcc909873d |
comparison
equal
deleted
inserted
replaced
119:0f24800e9ca8 | 120:9b08afeadf06 |
---|---|
17 | 17 |
18 def __init__(self): | 18 def __init__(self): |
19 Sprite.__init__(self) | 19 Sprite.__init__(self) |
20 self.image = None | 20 self.image = None |
21 self._image_dict = {} | 21 self._image_dict = {} |
22 self._animation_frame = 0.0 | |
22 # State flags and such | 23 # State flags and such |
23 self.running = False | 24 self.running = False |
24 self.jumping = False | 25 self.jumping = False |
25 self.flying = False | 26 self.flying = False |
26 self._load_images() | 27 self._load_images() |
31 self.set_pos((0, 0)) | 32 self.set_pos((0, 0)) |
32 self._layer = Layers.PLAYER | 33 self._layer = Layers.PLAYER |
33 | 34 |
34 def set_image(self): | 35 def set_image(self): |
35 key = self._make_key() | 36 key = self._make_key() |
36 # TODO: handle animations | 37 images = self._image_dict[key] |
37 self.image = self._image_dict[key][0] | 38 if self._animation_frame >= len(images): |
39 self._animation_frame = 0.0 | |
40 self.image = images[int(self._animation_frame)] | |
38 | 41 |
39 def update(self): | 42 def update(self): |
40 pass # animate tail here | 43 v_x, v_y = self.velocity |
44 self._animation_frame += abs(v_x) / 3000.0 | |
45 if v_x == 0: | |
46 self.running = False | |
47 else: | |
48 self.running = True | |
49 self.set_image() | |
41 | 50 |
42 def set_facing(self, new_facing): | 51 def set_facing(self, new_facing): |
43 self.facing = new_facing | 52 self.facing = new_facing |
44 | 53 |
45 def set_pos(self, pos): | 54 def set_pos(self, pos): |
105 continue | 114 continue |
106 image = load_image(os.path.join(directory, image_file)) | 115 image = load_image(os.path.join(directory, image_file)) |
107 if facing == 'right': | 116 if facing == 'right': |
108 image = pygame.transform.flip(image, True, False) | 117 image = pygame.transform.flip(image, True, False) |
109 self._image_dict[key].append(image) | 118 self._image_dict[key].append(image) |
110 | |
111 |