changeset 411:a5f54ae9217e

Per weapon recharge
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 09 Apr 2011 17:35:11 +0200
parents 115e738e209c
children 8ac5b3d619fe
files skaapsteker/constants.py skaapsteker/levelscene.py skaapsteker/sprites/player.py
diffstat 3 files changed, 17 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/constants.py	Sat Apr 09 17:30:09 2011 +0200
+++ b/skaapsteker/constants.py	Sat Apr 09 17:35:11 2011 +0200
@@ -58,11 +58,5 @@
     HEALTH_HEIGHT = 160
     HEALTH_WIDTH = 20
 
-    RECHARGE_BACKGROUND = pygame.Color(64, 128, 0, 128)
-    RECHARGE_FOREGROUND = pygame.Color(64, 255, 0, 196)
-    RECHARGE_TOP = 220
-    RECHARGE_WIDTH = 50
-    RECHARGE_HEIGHT = 15
-
-    SCROLL_TOP = 240
-    TOFU_TOP = 270
+    SCROLL_TOP = 220
+    TOFU_TOP = 250
--- a/skaapsteker/levelscene.py	Sat Apr 09 17:30:09 2011 +0200
+++ b/skaapsteker/levelscene.py	Sat Apr 09 17:35:11 2011 +0200
@@ -254,14 +254,6 @@
         bar.bottomleft = health_bottom
         pygame.draw.rect(self._level_surface, fox_hud.HEALTH_FOREGROUND, bar)
 
-        # Draw fire recharge bar
-        recharge = pygame.Rect(self._clip_rect.right - 55,
-                               self._clip_rect.top + fox_hud.RECHARGE_TOP,
-                               fox_hud.RECHARGE_WIDTH, fox_hud.RECHARGE_HEIGHT)
-        pygame.draw.rect(self._level_surface, fox_hud.RECHARGE_BACKGROUND, recharge)
-        recharge.width = int(fox_hud.RECHARGE_WIDTH * self._player.recharge_level())
-        pygame.draw.rect(self._level_surface, fox_hud.RECHARGE_FOREGROUND, recharge)
-
         # Draw scroll count
         pos = self._clip_rect.right - 20, self._clip_rect.top + fox_hud.SCROLL_TOP + 5
         count = Text("%s" % len(fox.scrolls), pos)
--- a/skaapsteker/sprites/player.py	Sat Apr 09 17:30:09 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sat Apr 09 17:35:11 2011 +0200
@@ -12,7 +12,6 @@
 
 from pygame.constants import BLEND_RGBA_MULT
 
-
 class Player(Sprite):
 
     collision_layer = PC_LAYER
@@ -31,7 +30,10 @@
         self._soundsystem.load_sound('yelp', 'sounds/yelp.ogg')
         self._animation_frame = 0.0
         self._last_time = time.time()
-        self._last_fired = time.time()
+        self._last_attacked = {
+                'fireball': time.time(),
+                'lightning': time.time(),
+        }
         self._inv_cache = {}
         # State flags and such
         self.attacking = 0
@@ -240,7 +242,6 @@
         self.flying = 1
         self._max_flight_time = float(len(self._me.tails))
         self._flight_start_time = time.time()
-
     def action_invisible(self):
         if self.invisible > 0 or 'invisibility' not in self._me.tails:
             return
@@ -313,19 +314,23 @@
         AddSpriteEvent.post(projectile)
 
     def _fireball_attack(self):
+        if not self.check_fire_rate('fireball'):
+            return
         self.invisible = 0
         self.attacking = 2
         self._last_time = time.time() # Reset the animation clock
         self._launch_projectile(Fireball)
 
     def _lightning_attack(self):
+        if not self.check_fire_rate('lightning'):
+            return
         self.invisible = 0
         self.attacking = 2
         self._last_time = time.time() # Reset the animation clock
         self._launch_projectile(Lightning)
 
     def action_fire1(self):
-        if self._me.shape != 'fox' or not self.check_fire_rate():
+        if self._me.shape != 'fox':
             return
         if "fireball" not in self._me.tails:
             self._bite_attack()
@@ -333,21 +338,21 @@
             self._fireball_attack()
 
     def action_fire2(self):
-        if self._me.shape != 'fox' or not self.check_fire_rate():
+        if self._me.shape != 'fox':
             return
         if "lightning" not in self._me.tails:
             self._bite_attack()
         else:
             self._lightning_attack()
 
-    def check_fire_rate(self):
-        if self.recharge_level() < 1:
+    def check_fire_rate(self, attack):
+        if self.recharge_level(attack) < 1:
             return False
-        self._last_fired = time.time()
+        self._last_attacked[attack] = time.time()
         return True
 
-    def recharge_level(self):
-        return min((time.time() - self._last_fired) / RECHARGE_TIME, 1)
+    def recharge_level(self, attack):
+        return min((time.time() - self._last_attacked[attack]) / RECHARGE_TIME, 1)
 
     def _get_action(self):
         if self.attacking: