comparison pytouhou/game/enemy.py @ 318:1366cefd0334

Move callbacks handling inside Enemy.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 17 May 2012 14:15:19 +0200
parents f0be7ea62330
children 9a4119e2cc74
comparison
equal deleted inserted replaced
317:8579c43c124c 318:1366cefd0334
338 338
339 # Apply damages 339 # Apply damages
340 self.life -= damages 340 self.life -= damages
341 341
342 342
343 def handle_callbacks(self):
344 #TODO: implement missing callbacks and clean up!
345 if self.life <= 0 and self.touchable:
346 death_flags = self.death_flags & 7
347
348 self.die_anim()
349
350 if death_flags < 4:
351 if self.bonus_dropped > -1:
352 self.drop_particles(7, 0)
353 self._game.drop_bonus(self.x, self.y, self.bonus_dropped)
354 elif self.bonus_dropped == -1:
355 if self._game.deaths_count % 3 == 0:
356 self.drop_particles(10, 0)
357 self._game.drop_bonus(self.x, self.y, self._game.bonus_list[self._game.next_bonus])
358 self._game.next_bonus = (self._game.next_bonus + 1) % 32
359 else:
360 self.drop_particles(4, 0)
361 self._game.deaths_count += 1
362 else:
363 self.drop_particles(4, 0)
364
365 if death_flags == 0:
366 self.removed = True
367 return
368
369 if death_flags == 1:
370 self.touchable = False
371 elif death_flags == 2:
372 pass # Just that?
373 elif death_flags == 3:
374 #TODO: disable boss mode
375 self.damageable = False
376 self.life = 1
377 self.death_flags = 0
378
379 if death_flags != 0 and self.death_callback > -1:
380 self.process.switch_to_sub(self.death_callback)
381 self.death_callback = -1
382 elif self.life <= self.low_life_trigger and self.low_life_callback > -1:
383 self.process.switch_to_sub(self.low_life_callback)
384 self.low_life_callback = -1
385 elif self.timeout != -1 and self.frame == self.timeout:
386 self.frame = 0
387 if self.timeout_callback > -1:
388 self.process.switch_to_sub(self.timeout_callback)
389 self.timeout_callback = -1
390 elif self.touchable:
391 self.life = 0
392 elif self.death_callback > -1:
393 self.process.switch_to_sub(self.death_callback)
394 self.death_callback = -1
395 self.timeout = -1 #TODO: check
396 else:
397 raise Exception('What the hell, man!')
398
399
343 def update(self): 400 def update(self):
344 if self.process: 401 if self.process:
345 self.process.run_iteration() 402 self.process.run_iteration()
403 self.handle_callbacks()
346 404
347 x, y = self.x, self.y 405 x, y = self.x, self.y
348 406
349 if self.update_mode == 1: 407 if self.update_mode == 1:
350 speed = 0.0 408 speed = 0.0