comparison pytouhou/game/enemy.py @ 268:dd621ad72beb

Fix callback handling and damage dealing.
author Thibaut Girka <thib@sitedethib.com>
date Mon, 23 Jan 2012 23:00:42 +0100
parents ea4832f843aa
children 7a9135b88853
comparison
equal deleted inserted replaced
267:35644a67ba4c 268:dd621ad72beb
46 self.boss = False 46 self.boss = False
47 self.difficulty_coeffs = (-.5, .5, 0, 0, 0, 0) 47 self.difficulty_coeffs = (-.5, .5, 0, 0, 0, 0)
48 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.) 48 self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.)
49 self.bullet_attributes = None 49 self.bullet_attributes = None
50 self.bullet_launch_offset = (0, 0) 50 self.bullet_launch_offset = (0, 0)
51 self.death_callback = None 51 self.death_callback = -1
52 self.boss_callback = None 52 self.boss_callback = None
53 self.low_life_callback = None 53 self.low_life_callback = -1
54 self.low_life_trigger = None 54 self.low_life_trigger = None
55 self.timeout = None 55 self.timeout = -1
56 self.timeout_callback = None 56 self.timeout_callback = -1
57 self.remaining_lives = -1 57 self.remaining_lives = -1
58 58
59 self.automatic_orientation = False 59 self.automatic_orientation = False
60 60
61 self.bullet_launch_interval = 0 61 self.bullet_launch_interval = 0
260 by1, by2 = by - half_size[1], by + half_size[1] 260 by1, by2 = by - half_size[1], by + half_size[1]
261 261
262 if not (bx2 < ex1 or bx1 > ex2 262 if not (bx2 < ex1 or bx1 > ex2
263 or by2 < ey1 or by1 > ey2): 263 or by2 < ey1 or by1 > ey2):
264 bullet.collide() 264 bullet.collide()
265 damages += bullet.damage 265 if self.damageable:
266 damages += bullet.damage
266 self.drop_particles(1, 1) 267 self.drop_particles(1, 1)
267 268
268 # Check for enemy-player collisions 269 # Check for enemy-player collisions
269 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3. 270 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3.
270 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3. 271 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3.
291 damages = 1 if damages else 0 292 damages = 1 if damages else 0
292 else: 293 else:
293 damages //= 7 294 damages //= 7
294 295
295 # Apply damages 296 # Apply damages
296 if self.damageable: 297 self.life -= damages
297 self.life -= damages
298 298
299 299
300 def update(self): 300 def update(self):
301 x, y = self.x, self.y 301 x, y = self.x, self.y
302 302