# HG changeset patch # User Simon Cross # Date 1302365882 -7200 # Node ID 29e376484f3127192752f16c0db2a7fe28c87939 # Parent fc3b5460d454bcd32a71509fc39a2c186eea4dc2 Start of shield for player. diff -r fc3b5460d454 -r 29e376484f31 skaapsteker/sprites/player.py --- 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)