# HG changeset patch # User Neil Muller # Date 1302269642 -7200 # Node ID be516ca5e3b80512b6fdcf196e3132a2ffd12299 # Parent 7628467eecd990d35940afd450c8a04d1655c92f Add sprinting diff -r 7628467eecd9 -r be516ca5e3b8 skaapsteker/sprites/player.py --- a/skaapsteker/sprites/player.py Fri Apr 08 15:06:24 2011 +0200 +++ b/skaapsteker/sprites/player.py Fri Apr 08 15:34:02 2011 +0200 @@ -16,6 +16,8 @@ collides_with = set([MONSTER_LAYER]) wants_updates = True + _max_sprint_time = 2 + def __init__(self, the_world, soundsystem): Sprite.__init__(self) self.image = None @@ -28,6 +30,7 @@ # State flags and such self.attacking = 0 self.running = False + self.sprinting = False self.jumping = False self.flying = False self._load_images() @@ -91,6 +94,9 @@ # Force animation frame jump self._animation_frame = old_frame + 1 self._last_time = time.time() + if self.sprinting: + if (time.time() - self._sprint_start_time) > self._max_sprint_time: + self.sprinting = False if abs(v_x) < 80: # Clamp when we're not moving at least 5 pixel / s self.velocity = (0, v_y) @@ -174,13 +180,36 @@ if self.facing != 'left': self.facing = 'left' self.set_image() - self.deltav((-450.0, 0.0)) + if self.sprinting: + self.deltav((-900.0, 0.0)) + else: + self.deltav((-450.0, 0.0)) + + def action_double_left(self): + # FIXME: Tie this to the tails + if self.sprinting: + return + self.sprinting = True + self._sprint_start_time = time.time() + + def action_double_down(self): + print 'double down tap' + + def action_double_right(self): + if self.sprinting: + return + self.sprinting = True + self._sprint_start_time = time.time() def action_right(self): if self.facing != 'right': self.facing = 'right' self.set_image() - self.deltav((450.0, 0.0)) + if self.sprinting: + self.deltav((900.0, 0.0)) + else: + self.deltav((450.0, 0.0)) + def action_up(self): if self.on_solid: @@ -204,6 +233,8 @@ def _get_action(self): if self.attacking: return 'attacking' + if self.sprinting and self.running: + return 'sprinting' if self.running: return 'running' if self.jumping: @@ -232,9 +263,20 @@ # Skip extra junk for now continue image = load_image('%s/%s' % (directory, image_file)) + if action == 'running': + sprint_key = self._make_key(tails, 'sprinting') + if sprint_key not in self._image_dict: + self._image_dict[sprint_key] = [] + shockwave = load_image('sprites/kitsune_shockwave.png') + if facing == 'right': + shockwave = pygame.transform.flip(shockwave, True, False) if facing == 'right': image = pygame.transform.flip(image, True, False) self._image_dict[key].append(image) + if action == 'running': + sprint_image = image.copy() + sprint_image.blit(shockwave, (0, 0)) + self._image_dict[sprint_key].append(sprint_image) def take_item(self, item):