changeset 430:25efc74ac19c

Hook up flight and invisibility discharge
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 09 Apr 2011 18:40:25 +0200
parents 8b047e74dfd1
children b753ea36909e
files skaapsteker/levelscene.py skaapsteker/sprites/player.py
diffstat 2 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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'