Changeset 426:29e376484f31


Ignore:
Timestamp:
04/09/11 16:18:02 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
62346131653265373532336131326137323932393064626464633136353235633635656639306336
Message:

Start of shield for player.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/player.py

    r411 r426  
    3434                'fireball': time.time(),
    3535                'lightning': time.time(),
     36                'shield': time.time(),
    3637        }
    37         self._inv_cache = {}
     38        self._inv_cache = {} # invisible fox image cache
     39        self._shield_cache = {} # shielded fox image cache
     40        self._shield_image = 0 # shield image
    3841        # State flags and such
    3942        self.attacking = 0
     
    4447        self.prep_flight = 0.0
    4548        self.invisible = 0
     49        self.using_shield = 0
    4650        self.shape = 'fox'  # Needed so load image does the right thing
    4751        self._load_images()
     
    8589                cand_image.fill((0, 0, 0, 140), None, BLEND_RGBA_MULT)
    8690                self._inv_cache[id_cand_image] = cand_image
     91        if self.using_shield > 0:
     92            id_cand_image = id(cand_image)
     93            if id_cand_image in self._shield_cache:
     94                cand_image = self._shield_cache[id_cand_image]
     95            else:
     96                cand_image = cand_image.copy()
     97                cand_image.blit(self._shield_image)
     98                self._shield_cache[id_cand_image] = cand_image
    8799        self.image = cand_image
    88100        self.collide_rect = cand_collide_rect
     
    129141            if (now - self._invisibility_start_time) > self._max_invisibility_time:
    130142                self.invisible = 0
     143        if self.using_shield > 0:
     144            self.using_shield -= 1
    131145        if abs(v_x) < 80:
    132146            # Clamp when we're not moving at least 5 pixel / s
     
    196210
    197211    def damage(self, damage):
     212        if 'shield' in self._me.tails and self.check_fire_rate('shield'):
     213            self.using_shield = 3
     214            return
    198215        self._me.cur_health -= damage
    199216        self._soundsystem.play_sound('yelp')
     
    243260        self._max_flight_time = float(len(self._me.tails))
    244261        self._flight_start_time = time.time()
     262
    245263    def action_invisible(self):
    246264        if self.invisible > 0 or 'invisibility' not in self._me.tails:
     
    384402
    385403    def _load_images(self):
     404        self._shield_image = load_image('sprites/kitsune_shield.png')
    386405        for action in ['standing', 'running', 'jumping', 'attacking']:
    387406            for tails in [0, 1, 2, 4]:
Note: See TracChangeset for help on using the changeset viewer.