Ignore:
Timestamp:
Sep 6, 2013, 7:56:57 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Automatic weapons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/protagonist.py

    r370 r371  
    99    PROTAGONIST_HEALTH_MIN_LEVEL, PROTAGONIST_HEALTH_MAX_LEVEL,
    1010    NON_GAME_OBJECT_COLLIDERS, BULLET_DAMAGE, BULLET_SPEED, CLAW_DAMAGE,
    11     CMD_TOGGLE_FORM, CMD_ATTACK, CMD_ACTION)
     11    CMD_TOGGLE_FORM, CMD_ACTION)
    1212from nagslang.events import FireEvent, ClawEvent
    1313from nagslang.game_object import GameObject, Physicser, make_body
     
    7979        self.is_moving = False
    8080        self.changing_sequence = []
    81         self.change_delay = 0
     81        self.add_timer('attack_cooldown', 0.2)
     82        self.add_timer('change_delay', 0.1)
    8283
    8384        self.go_human()
     
    188189        return obj
    189190
     191    def handle_attack_key_down(self):
     192        if self.changing_sequence or self.check_timer('attack_cooldown'):
     193            return
     194        self.start_timer('attack_cooldown')
     195        self.world.attacks += 1
     196        self.attack()
     197
    190198    def handle_keypress(self, key_command):
    191199        if self.changing_sequence:
    192             print "Changing, can't act."
    193200            return
    194201        if key_command == CMD_TOGGLE_FORM:
    195202            self.world.transformations += 1
    196203            self.toggle_form()
    197         if key_command == CMD_ATTACK:
    198             self.world.attacks += 1
    199             self.attack()
    200204        if key_command == CMD_ACTION:
    201205            self.perform_action()
     
    256260
    257261    def toggle_form(self):
    258         if self.change_delay:
     262        if self.check_timer('change_delay'):
    259263            return
    260264        self.changing_sequence.extend(self.CHANGING_SEQUENCE[self.form])
     
    353357            self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL
    354358
     359    def _decrement_timer(self, timer, dt):
     360        if self._timers[timer] > 0:
     361            self._timers[timer] -= dt
     362        if self._timers[timer] < 0:
     363            self._timers[timer] = 0
     364
    355365    def update(self, dt):
    356         if self.change_delay > 0:
    357             self.change_delay -= 1
    358366        if self.changing_sequence:
    359367            self._go_to_next_form()
     
    366374        if self.in_human_form() and not self.changing_sequence:
    367375            self.toggle_form()
    368         self.change_delay = 2
     376        self.start_timer('change_delay')
Note: See TracChangeset for help on using the changeset viewer.