Mercurial > skaapsteker
diff skaapsteker/sprites/player.py @ 408:bbfc2cc07ba4
Add invisibility power.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 17:23:07 +0200 |
parents | 6850a3ab3aac |
children | 115e738e209c |
line wrap: on
line diff
--- a/skaapsteker/sprites/player.py Sat Apr 09 17:18:11 2011 +0200 +++ b/skaapsteker/sprites/player.py Sat Apr 09 17:23:07 2011 +0200 @@ -10,6 +10,8 @@ from ..data import get_files, load_image from ..engine import PlayerDied, AddSpriteEvent, OpenNotification +from pygame.constants import BLEND_RGBA_MULT + class Player(Sprite): @@ -30,13 +32,15 @@ self._animation_frame = 0.0 self._last_time = time.time() self._last_fired = time.time() + self._inv_cache = {} # State flags and such self.attacking = 0 self.running = False self.sprinting = 0 self.jumping = False - self.flying = False + self.flying = 0 self.prep_flight = 0.0 + self.invisible = 0 self.shape = 'fox' # Needed so load image does the right thing self._load_images() self.inventory_image = None @@ -70,6 +74,14 @@ # We always allow the attacking animation frames if not self.check_collide_rect(cand_collide_rect, cand_rect, cand_image) and not self.attacking: return False + if self.invisible > 0: + id_cand_image = id(cand_image) + if id_cand_image in self._inv_cache: + cand_image = self._inv_cache[id_cand_image] + else: + cand_image = cand_image.copy() + cand_image.fill((0, 0, 0, 140), None, BLEND_RGBA_MULT) + self._inv_cache[id_cand_image] = cand_image self.image = cand_image self.collide_rect = cand_collide_rect self.rect = cand_rect @@ -111,7 +123,9 @@ if self.flying > 0: if (now - self._flight_start_time) > self._max_flight_time: self.flying = 0 - # v_y = 0 # Standard platformer flying + if self.invisible > 0: + if (now - self._invisibility_start_time) > self._max_invisibility_time: + self.invisible = 0 if abs(v_x) < 80: # Clamp when we're not moving at least 5 pixel / s self.velocity = (0, v_y) @@ -227,6 +241,13 @@ 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 + self.invisible = 1 + self._max_invisibility_time = float(len(self._me.tails)) + self._invisibility_start_time = time.time() + def action_transform(self): """Transform the fox""" if not self.on_solid: