comparison pytouhou/game/enemy.py @ 408:c689ff1743bf

Do the correct score calculation even when the enemy isn’t damageable.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 09 Jun 2013 22:54:33 +0200
parents b11953cf1d3b
children c9433188ffdb
comparison
equal deleted inserted replaced
407:b4be9b50557e 408:c689ff1743bf
311 by1, by2 = by - half_size[1], by + half_size[1] 311 by1, by2 = by - half_size[1], by + half_size[1]
312 312
313 if not (bx2 < ex1 or bx1 > ex2 313 if not (bx2 < ex1 or bx1 > ex2
314 or by2 < ey1 or by1 > ey2): 314 or by2 < ey1 or by1 > ey2):
315 bullet.collide() 315 bullet.collide()
316 if self.damageable: 316 damages += bullet.damage
317 damages += bullet.damage
318 self._game.sfx_player.play('damage00.wav') 317 self._game.sfx_player.play('damage00.wav')
319 318
320 # Check for enemy-laser collisions 319 # Check for enemy-laser collisions
321 for laser in self._game.players_lasers: 320 for laser in self._game.players_lasers:
322 if not laser: 321 if not laser:
326 lx, ly = laser.x, laser.y * 2. 325 lx, ly = laser.x, laser.y * 2.
327 lx1, lx2 = lx - half_size[0], lx + half_size[0] 326 lx1, lx2 = lx - half_size[0], lx + half_size[0]
328 327
329 if not (lx2 < ex1 or lx1 > ex2 328 if not (lx2 < ex1 or lx1 > ex2
330 or ly < ey1): 329 or ly < ey1):
331 if self.damageable: 330 damages += laser.damage
332 damages += laser.damage
333 self._game.sfx_player.play('damage00.wav') 331 self._game.sfx_player.play('damage00.wav')
334 self.drop_particles(1, 1) #TODO: don’t call each frame. 332 self.drop_particles(1, 1) #TODO: don’t call each frame.
335 333
336 # Check for enemy-player collisions 334 # Check for enemy-player collisions
337 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3. 335 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3.
352 # Adjust damages 350 # Adjust damages
353 damages = min(70, damages) 351 damages = min(70, damages)
354 score = (damages // 5) * 10 352 score = (damages // 5) * 10
355 self._game.players[0].state.score += score #TODO: better distribution amongst the players. 353 self._game.players[0].state.score += score #TODO: better distribution amongst the players.
356 354
357 if self._game.spellcard: 355 if self.damageable:
358 #TODO: there is a division by 3, somewhere... where is it? 356 if self._game.spellcard:
359 if damages <= 7: 357 #TODO: there is a division by 3, somewhere... where is it?
360 damages = 1 if damages else 0 358 if damages <= 7:
361 else: 359 damages = 1 if damages else 0
362 damages //= 7 360 else:
363 361 damages //= 7
364 # Apply damages 362
365 self.life -= damages 363 # Apply damages
364 self.life -= damages
366 365
367 366
368 def handle_callbacks(self): 367 def handle_callbacks(self):
369 #TODO: implement missing callbacks and clean up! 368 #TODO: implement missing callbacks and clean up!
370 if self.life <= 0 and self.touchable: 369 if self.life <= 0 and self.touchable: