Mercurial > skaapsteker
diff skaapsteker/sprites/player.py @ 411:a5f54ae9217e
Per weapon recharge
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sat, 09 Apr 2011 17:35:11 +0200 |
parents | 115e738e209c |
children | 29e376484f31 |
line wrap: on
line diff
--- 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: