# HG changeset patch # User Stefano Rivera # Date 1302367225 -7200 # Node ID 25efc74ac19c5fe15f99e7f1703a3d0b4906ed82 # Parent 8b047e74dfd181893c92d01c044c900701d08a88 Hook up flight and invisibility discharge diff -r 8b047e74dfd1 -r 25efc74ac19c skaapsteker/levelscene.py --- a/skaapsteker/levelscene.py Sat Apr 09 18:23:59 2011 +0200 +++ b/skaapsteker/levelscene.py Sat Apr 09 18:40:25 2011 +0200 @@ -241,17 +241,22 @@ # Draw tails for tail, position in constants.FoxHud.TAIL_POSITIONS.iteritems(): has_tail = tail in fox.tails - tail_pos = (self._clip_rect.left + fox_hud.TAILS_BG_MARGIN, - self._clip_rect.top + fox_hud.TAIL_POSITIONS[tail]) + tail_pos = pygame.Rect(self._clip_rect.left + fox_hud.TAILS_BG_MARGIN, + self._clip_rect.top + fox_hud.TAIL_POSITIONS[tail], + 0, 0) - if has_tail and tail in ('fireball', 'lightning'): - imgs = self._tails[tail] - size = imgs[0].get_size() + imgs = self._tails[tail] + size = imgs[0].get_size() + if has_tail and tail in ('flight', 'invisibility'): + area = pygame.Rect(self._player.discharge_level(tail) * size[0], 0, size[0], size[1]) + self._level_surface.blit(imgs[0], tail_pos) + self._level_surface.blit(imgs[1], tail_pos.move(area.left, 0), area) + elif has_tail and tail in ('fireball', 'lightning', 'shield'): area = pygame.Rect(0, 0, self._player.recharge_level(tail) * size[0], size[1]) self._level_surface.blit(imgs[0], tail_pos) self._level_surface.blit(imgs[1], tail_pos, area) else: - self._level_surface.blit(self._tails[tail][int(has_tail)], tail_pos) + self._level_surface.blit(imgs[int(has_tail)], tail_pos) # Draw the health bar health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200 diff -r 8b047e74dfd1 -r 25efc74ac19c skaapsteker/sprites/player.py --- a/skaapsteker/sprites/player.py Sat Apr 09 18:23:59 2011 +0200 +++ b/skaapsteker/sprites/player.py Sat Apr 09 18:40:25 2011 +0200 @@ -391,6 +391,20 @@ def recharge_level(self, attack): return min((time.time() - self._last_attacked[attack]) / RECHARGE_TIME, 1) + def discharge_level(self, tail): + if tail == 'invisibility' and hasattr(self, '_invisibility_start_time'): + start_time = self._invisibility_start_time + max_time = self._max_invisibility_time + elif tail == 'flight' and hasattr(self, '_flight_start_time'): + start_time = self._flight_start_time + max_time = self._max_flight_time + else: + return 0 + discharge = (time.time() - start_time) / max_time + if discharge > 1: + return 0 + return discharge + def _get_action(self): if self.attacking: return 'attacking'