Mercurial > nagslang
diff nagslang/protagonist.py @ 371:21c1c329f8e3
Automatic weapons.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 21:56:57 +0200 |
parents | b5a0081f5784 |
children | 150332d6c1fb |
line wrap: on
line diff
--- a/nagslang/protagonist.py Fri Sep 06 21:37:00 2013 +0200 +++ b/nagslang/protagonist.py Fri Sep 06 21:56:57 2013 +0200 @@ -8,7 +8,7 @@ COLLISION_TYPE_PLAYER, ZORDER_MID, WEREWOLF_SOAK_FACTOR, PROTAGONIST_HEALTH_MIN_LEVEL, PROTAGONIST_HEALTH_MAX_LEVEL, NON_GAME_OBJECT_COLLIDERS, BULLET_DAMAGE, BULLET_SPEED, CLAW_DAMAGE, - CMD_TOGGLE_FORM, CMD_ATTACK, CMD_ACTION) + CMD_TOGGLE_FORM, CMD_ACTION) from nagslang.events import FireEvent, ClawEvent from nagslang.game_object import GameObject, Physicser, make_body from nagslang.mutators import FLIP_H @@ -78,7 +78,8 @@ self.angle = 0 self.is_moving = False self.changing_sequence = [] - self.change_delay = 0 + self.add_timer('attack_cooldown', 0.2) + self.add_timer('change_delay', 0.1) self.go_human() @@ -187,16 +188,19 @@ # TODO: Update from saved state. return obj + def handle_attack_key_down(self): + if self.changing_sequence or self.check_timer('attack_cooldown'): + return + self.start_timer('attack_cooldown') + self.world.attacks += 1 + self.attack() + def handle_keypress(self, key_command): if self.changing_sequence: - print "Changing, can't act." return if key_command == CMD_TOGGLE_FORM: self.world.transformations += 1 self.toggle_form() - if key_command == CMD_ATTACK: - self.world.attacks += 1 - self.attack() if key_command == CMD_ACTION: self.perform_action() @@ -255,7 +259,7 @@ self.inventory = old_protagonist.inventory def toggle_form(self): - if self.change_delay: + if self.check_timer('change_delay'): return self.changing_sequence.extend(self.CHANGING_SEQUENCE[self.form]) @@ -352,9 +356,13 @@ if self.health_level > PROTAGONIST_HEALTH_MAX_LEVEL: self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL + def _decrement_timer(self, timer, dt): + if self._timers[timer] > 0: + self._timers[timer] -= dt + if self._timers[timer] < 0: + self._timers[timer] = 0 + def update(self, dt): - if self.change_delay > 0: - self.change_delay -= 1 if self.changing_sequence: self._go_to_next_form() if int(self.lifetime + dt) > int(self.lifetime): @@ -365,4 +373,4 @@ def force_wolf_form(self): if self.in_human_form() and not self.changing_sequence: self.toggle_form() - self.change_delay = 2 + self.start_timer('change_delay')