comparison 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
comparison
equal deleted inserted replaced
370:b5a0081f5784 371:21c1c329f8e3
6 from nagslang import render 6 from nagslang import render
7 from nagslang.constants import ( 7 from nagslang.constants import (
8 COLLISION_TYPE_PLAYER, ZORDER_MID, WEREWOLF_SOAK_FACTOR, 8 COLLISION_TYPE_PLAYER, ZORDER_MID, WEREWOLF_SOAK_FACTOR,
9 PROTAGONIST_HEALTH_MIN_LEVEL, PROTAGONIST_HEALTH_MAX_LEVEL, 9 PROTAGONIST_HEALTH_MIN_LEVEL, PROTAGONIST_HEALTH_MAX_LEVEL,
10 NON_GAME_OBJECT_COLLIDERS, BULLET_DAMAGE, BULLET_SPEED, CLAW_DAMAGE, 10 NON_GAME_OBJECT_COLLIDERS, BULLET_DAMAGE, BULLET_SPEED, CLAW_DAMAGE,
11 CMD_TOGGLE_FORM, CMD_ATTACK, CMD_ACTION) 11 CMD_TOGGLE_FORM, CMD_ACTION)
12 from nagslang.events import FireEvent, ClawEvent 12 from nagslang.events import FireEvent, ClawEvent
13 from nagslang.game_object import GameObject, Physicser, make_body 13 from nagslang.game_object import GameObject, Physicser, make_body
14 from nagslang.mutators import FLIP_H 14 from nagslang.mutators import FLIP_H
15 from nagslang.resources import resources 15 from nagslang.resources import resources
16 from nagslang.events import ScreenChange 16 from nagslang.events import ScreenChange
76 self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL 76 self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL
77 77
78 self.angle = 0 78 self.angle = 0
79 self.is_moving = False 79 self.is_moving = False
80 self.changing_sequence = [] 80 self.changing_sequence = []
81 self.change_delay = 0 81 self.add_timer('attack_cooldown', 0.2)
82 self.add_timer('change_delay', 0.1)
82 83
83 self.go_human() 84 self.go_human()
84 85
85 def _make_physics(self, space, position): 86 def _make_physics(self, space, position):
86 body = make_body(10, pymunk.inf, position, 0.8) 87 body = make_body(10, pymunk.inf, position, 0.8)
185 """ 186 """
186 obj = cls() 187 obj = cls()
187 # TODO: Update from saved state. 188 # TODO: Update from saved state.
188 return obj 189 return obj
189 190
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
190 def handle_keypress(self, key_command): 198 def handle_keypress(self, key_command):
191 if self.changing_sequence: 199 if self.changing_sequence:
192 print "Changing, can't act."
193 return 200 return
194 if key_command == CMD_TOGGLE_FORM: 201 if key_command == CMD_TOGGLE_FORM:
195 self.world.transformations += 1 202 self.world.transformations += 1
196 self.toggle_form() 203 self.toggle_form()
197 if key_command == CMD_ATTACK:
198 self.world.attacks += 1
199 self.attack()
200 if key_command == CMD_ACTION: 204 if key_command == CMD_ACTION:
201 self.perform_action() 205 self.perform_action()
202 206
203 def get_render_angle(self): 207 def get_render_angle(self):
204 # No image rotation when rendering, please. 208 # No image rotation when rendering, please.
253 self.form = old_protagonist.form 257 self.form = old_protagonist.form
254 self.angle = old_protagonist.angle 258 self.angle = old_protagonist.angle
255 self.inventory = old_protagonist.inventory 259 self.inventory = old_protagonist.inventory
256 260
257 def toggle_form(self): 261 def toggle_form(self):
258 if self.change_delay: 262 if self.check_timer('change_delay'):
259 return 263 return
260 self.changing_sequence.extend(self.CHANGING_SEQUENCE[self.form]) 264 self.changing_sequence.extend(self.CHANGING_SEQUENCE[self.form])
261 265
262 def _go_to_next_form(self): 266 def _go_to_next_form(self):
263 if self.changing_sequence.pop(0) == self.WOLF_FORM: 267 if self.changing_sequence.pop(0) == self.WOLF_FORM:
350 def gain_health(self, amount): 354 def gain_health(self, amount):
351 self.health_level += amount 355 self.health_level += amount
352 if self.health_level > PROTAGONIST_HEALTH_MAX_LEVEL: 356 if self.health_level > PROTAGONIST_HEALTH_MAX_LEVEL:
353 self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL 357 self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL
354 358
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
355 def update(self, dt): 365 def update(self, dt):
356 if self.change_delay > 0:
357 self.change_delay -= 1
358 if self.changing_sequence: 366 if self.changing_sequence:
359 self._go_to_next_form() 367 self._go_to_next_form()
360 if int(self.lifetime + dt) > int(self.lifetime): 368 if int(self.lifetime + dt) > int(self.lifetime):
361 if self.in_wolf_form(): 369 if self.in_wolf_form():
362 self.gain_health(1) 370 self.gain_health(1)
363 super(Protagonist, self).update(dt) 371 super(Protagonist, self).update(dt)
364 372
365 def force_wolf_form(self): 373 def force_wolf_form(self):
366 if self.in_human_form() and not self.changing_sequence: 374 if self.in_human_form() and not self.changing_sequence:
367 self.toggle_form() 375 self.toggle_form()
368 self.change_delay = 2 376 self.start_timer('change_delay')