Mercurial > nagslang
diff nagslang/enemies.py @ 308:3dee86b6c216
Enemies leave corpses
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Fri, 06 Sep 2013 00:36:14 +0200 |
parents | c2bbb1e70d6f |
children | fa408430a174 |
line wrap: on
line diff
--- a/nagslang/enemies.py Fri Sep 06 00:32:38 2013 +0200 +++ b/nagslang/enemies.py Fri Sep 06 00:36:14 2013 +0200 @@ -4,7 +4,9 @@ import pymunk.pygame_util from nagslang import render -from nagslang.constants import COLLISION_TYPE_ENEMY, ZORDER_MID +from nagslang.constants import (COLLISION_TYPE_ENEMY, COLLISION_TYPE_BOX, + ZORDER_MID) +from nagslang.events import EnemyDeathEvent from nagslang.game_object import GameObject, SingleShapePhysicser, make_body from nagslang.mutators import FLIP_H from nagslang.resources import resources @@ -21,6 +23,7 @@ class Enemy(GameObject): """A base class for mobile enemies""" + enemy_type = None # Image to use for dead Enemy def __init__(self, space, world, position): self._setup_physics(space, position) @@ -51,13 +54,32 @@ def lose_health(self, amount): self.health -= amount if self.health < 0: - self.world.kills += 1 self.physicser.remove_from_space() self.remove = True + EnemyDeathEvent.post(self.physicser.position, 'A') + + +class DeadEnemy(GameObject): + def __init__(self, space, world, position, enemy_type='A'): + body = make_body(10, 10000, position, damping=0.5) + self.shape = pymunk.Poly( + body, [(-20, -20), (20, -20), (20, 20), (-20, 20)]) + self.shape.friction = 0.5 + self.shape.collision_type = COLLISION_TYPE_BOX + super(DeadEnemy, self).__init__( + SingleShapePhysicser(space, self.shape), + render.ImageRenderer(resources.get_image( + 'creatures', 'alien_%s_dead.png' % enemy_type)), + ) + + @classmethod + def requires(cls): + return [("name", "string"), ("position", "coordinates")] class PatrollingAlien(Enemy): is_moving = True # Always walking. + enemy_type = 'A' def __init__(self, space, world, position, end_position): # An enemy that patrols between the two points @@ -150,6 +172,7 @@ class ChargingAlien(Enemy): # Simplistic charging of the protagonist is_moving = False + enemy_type = 'B' def __init__(self, space, world, position, attack_range=100): super(ChargingAlien, self).__init__(space, world, position)