changeset 426:29e376484f31

Start of shield for player.
author Simon Cross <hodgestar@gmail.com>
date Sat, 09 Apr 2011 18:18:02 +0200
parents fc3b5460d454
children 1e2eb4df061f
files skaapsteker/sprites/player.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/sprites/player.py	Sat Apr 09 18:21:37 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sat Apr 09 18:18:02 2011 +0200
@@ -33,8 +33,11 @@
         self._last_attacked = {
                 'fireball': time.time(),
                 'lightning': time.time(),
+                'shield': time.time(),
         }
-        self._inv_cache = {}
+        self._inv_cache = {} # invisible fox image cache
+        self._shield_cache = {} # shielded fox image cache
+        self._shield_image = 0 # shield image
         # State flags and such
         self.attacking = 0
         self.running = False
@@ -43,6 +46,7 @@
         self.flying = 0
         self.prep_flight = 0.0
         self.invisible = 0
+        self.using_shield = 0
         self.shape = 'fox'  # Needed so load image does the right thing
         self._load_images()
         self.inventory_image = None
@@ -84,6 +88,14 @@
                 cand_image = cand_image.copy()
                 cand_image.fill((0, 0, 0, 140), None, BLEND_RGBA_MULT)
                 self._inv_cache[id_cand_image] = cand_image
+        if self.using_shield > 0:
+            id_cand_image = id(cand_image)
+            if id_cand_image in self._shield_cache:
+                cand_image = self._shield_cache[id_cand_image]
+            else:
+                cand_image = cand_image.copy()
+                cand_image.blit(self._shield_image)
+                self._shield_cache[id_cand_image] = cand_image
         self.image = cand_image
         self.collide_rect = cand_collide_rect
         self.rect = cand_rect
@@ -128,6 +140,8 @@
         if self.invisible > 0:
             if (now - self._invisibility_start_time) > self._max_invisibility_time:
                 self.invisible = 0
+        if self.using_shield > 0:
+            self.using_shield -= 1
         if abs(v_x) < 80:
             # Clamp when we're not moving at least 5 pixel / s
             self.velocity = (0, v_y)
@@ -195,6 +209,9 @@
             other.collided_player(self)
 
     def damage(self, damage):
+        if 'shield' in self._me.tails and self.check_fire_rate('shield'):
+            self.using_shield = 3
+            return
         self._me.cur_health -= damage
         self._soundsystem.play_sound('yelp')
         if self._me.cur_health <= 0:
@@ -242,6 +259,7 @@
         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
@@ -383,6 +401,7 @@
         return '%s %s %d' % (action, self.facing, tails)
 
     def _load_images(self):
+        self._shield_image = load_image('sprites/kitsune_shield.png')
         for action in ['standing', 'running', 'jumping', 'attacking']:
             for tails in [0, 1, 2, 4]:
                 directory = 'sprites/kitsune_%s/kitsune_%s_%dtail' % (action, action, tails)