Mercurial > skaapsteker
comparison skaapsteker/sprites/player.py @ 435:b6fdaf8e453c
Make shield last for one second. Separate out recharge times to allow the shield to take longer to recharge.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 19:15:37 +0200 |
parents | fe99a4e04b2b |
children | 8ee16cec0f9f |
comparison
equal
deleted
inserted
replaced
434:827c5d045cf5 | 435:b6fdaf8e453c |
---|---|
29 self._soundsystem = soundsystem | 29 self._soundsystem = soundsystem |
30 self._soundsystem.load_sound('yelp', 'sounds/yelp.ogg') | 30 self._soundsystem.load_sound('yelp', 'sounds/yelp.ogg') |
31 self._animation_frame = 0.0 | 31 self._animation_frame = 0.0 |
32 self._last_time = time.time() | 32 self._last_time = time.time() |
33 self._recharge_timers = { | 33 self._recharge_timers = { |
34 'fireball': time.time(), | 34 'fireball': [ time.time(), lambda : 2.0 / len(self._me.tails) ], |
35 'lightning': time.time(), | 35 'lightning': [ time.time(), lambda : 2.0 / len(self._me.tails) ], |
36 'shield': time.time(), | 36 'shield': [ time.time(), lambda : 16.0 / len(self._me.tails) ], |
37 } | 37 } |
38 self._inv_cache = {} # invisible fox image cache | 38 self._inv_cache = {} # invisible fox image cache |
39 self._shield_cache = {} # shielded fox image cache | 39 self._shield_cache = {} # shielded fox image cache |
40 self._shield_image = 0 # shield image | 40 self._shield_image = 0 # shield image |
41 # State flags and such | 41 # State flags and such |
157 self.flying = 0 | 157 self.flying = 0 |
158 if self.invisible > 0: | 158 if self.invisible > 0: |
159 if (now - self._invisibility_start_time) > self._max_invisibility_time: | 159 if (now - self._invisibility_start_time) > self._max_invisibility_time: |
160 self.invisible = 0 | 160 self.invisible = 0 |
161 if self.using_shield > 0: | 161 if self.using_shield > 0: |
162 self.using_shield -= 1 | 162 if (now - self._shield_start_time) > 1.0: |
163 self.using_shield = 0 | |
163 if abs(v_x) < 80: | 164 if abs(v_x) < 80: |
164 # Clamp when we're not moving at least 5 pixel / s | 165 # Clamp when we're not moving at least 5 pixel / s |
165 self.velocity = (0, v_y) | 166 self.velocity = (0, v_y) |
166 if self.sprinting == 1: | 167 if self.sprinting == 1: |
167 self.sprinting = 0 | 168 self.sprinting = 0 |
225 self._collisions_seen += 1 | 226 self._collisions_seen += 1 |
226 if hasattr(other, 'collided_player'): | 227 if hasattr(other, 'collided_player'): |
227 other.collided_player(self) | 228 other.collided_player(self) |
228 | 229 |
229 def damage(self, damage): | 230 def damage(self, damage): |
230 if 'shield' in self._me.tails and self.check_fire_rate('shield'): | 231 if self.using_shield > 0: |
231 print "Using shield" | 232 "Shield on." |
232 self.using_shield = 30 | 233 return |
234 elif 'shield' in self._me.tails and self.check_fire_rate('shield'): | |
235 print "Activating shield." | |
236 self._shield_start_time = time.time() | |
237 self.using_shield = 1 | |
233 return | 238 return |
234 self._me.cur_health -= damage | 239 self._me.cur_health -= damage |
235 self._soundsystem.play_sound('yelp') | 240 self._soundsystem.play_sound('yelp') |
236 if self._me.cur_health <= 0: | 241 if self._me.cur_health <= 0: |
237 PlayerDied.post() | 242 PlayerDied.post() |
383 self._lightning_attack() | 388 self._lightning_attack() |
384 | 389 |
385 def check_fire_rate(self, attack): | 390 def check_fire_rate(self, attack): |
386 if self.recharge_level(attack) < 1: | 391 if self.recharge_level(attack) < 1: |
387 return False | 392 return False |
388 self._recharge_timers[attack] = time.time() | 393 self._recharge_timers[attack][0] = time.time() |
389 return True | 394 return True |
390 | 395 |
391 def recharge_level(self, attack): | 396 def recharge_level(self, attack): |
392 recharge_time = 2.0 / len(self._me.tails) | 397 recharge_time = self._recharge_timers[attack][1]() |
393 return min((time.time() - self._recharge_timers[attack]) / recharge_time, 1) | 398 return min((time.time() - self._recharge_timers[attack][0]) / recharge_time, 1) |
394 | 399 |
395 def discharge_level(self, tail): | 400 def discharge_level(self, tail): |
396 if tail == 'invisibility' and hasattr(self, '_invisibility_start_time'): | 401 if tail == 'invisibility' and hasattr(self, '_invisibility_start_time'): |
397 start_time = self._invisibility_start_time | 402 start_time = self._invisibility_start_time |
398 max_time = self._max_invisibility_time | 403 max_time = self._max_invisibility_time |