Mercurial > nagslang
changeset 305:ce11e1cae0ed
Enemies now die
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Fri, 06 Sep 2013 00:17:22 +0200 |
parents | 83477a7642b4 |
children | 3118589aeb11 |
files | nagslang/enemies.py nagslang/events.py nagslang/game_object.py nagslang/protagonist.py nagslang/screens/area.py |
diffstat | 5 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/nagslang/enemies.py Fri Sep 06 00:16:32 2013 +0200 +++ b/nagslang/enemies.py Fri Sep 06 00:17:22 2013 +0200 @@ -25,6 +25,7 @@ def __init__(self, space, world, position): self._setup_physics(space, position) self._setup_renderer() + self.health = 42 super(Enemy, self).__init__( self._physicser, self.renderer) @@ -47,6 +48,13 @@ def requires(cls): return [("name", "string"), ("position", "coordinates")] + def lose_health(self, amount): + self.health -= amount + if self.health < 0: + self.world.kills += 1 + self.physicser.remove_from_space() + self.remove = True + class PatrollingAlien(Enemy): is_moving = True # Always walking. @@ -130,6 +138,9 @@ def collide_with_protagonist(self, protagonist): protagonist.lose_health(15) + def hit(self, weapon): + self.lose_health(weapon.damage) + @classmethod def requires(cls): return [("name", "string"), ("position", "coordinates"),
--- a/nagslang/events.py Fri Sep 06 00:16:32 2013 +0200 +++ b/nagslang/events.py Fri Sep 06 00:17:22 2013 +0200 @@ -48,6 +48,7 @@ class FireEvent(UserEvent): @classmethod - def post(cls, source, impulse, source_collision_type): + def post(cls, source, impulse, damage, source_collision_type): super(FireEvent, cls).post(source=source, impulse=impulse, + damage=damage, source_collision_type=source_collision_type)
--- a/nagslang/game_object.py Fri Sep 06 00:16:32 2013 +0200 +++ b/nagslang/game_object.py Fri Sep 06 00:17:22 2013 +0200 @@ -342,12 +342,14 @@ class Bullet(GameObject): - def __init__(self, space, position, impulse, source_collision_type): + def __init__(self, space, position, impulse, damage, + source_collision_type): body = make_body(1, pymunk.inf, position) self.last_position = position self.shape = pymunk.Circle(body, 2) self.shape.sensor = True self.shape.collision_type = COLLISION_TYPE_PROJECTILE + self.damage = damage self.source_collision_type = source_collision_type super(Bullet, self).__init__( SingleShapePhysicser(space, self.shape),
--- a/nagslang/protagonist.py Fri Sep 06 00:16:32 2013 +0200 +++ b/nagslang/protagonist.py Fri Sep 06 00:17:22 2013 +0200 @@ -261,7 +261,7 @@ vec = Vec2d.unit() vec.angle = self.angle vec.length = 1000 - FireEvent.post(self.physicser.position, vec, COLLISION_TYPE_PLAYER) + FireEvent.post(self.physicser.position, vec, 10, COLLISION_TYPE_PLAYER) def in_wolf_form(self): return self.form == self.WOLF_FORM
--- a/nagslang/screens/area.py Fri Sep 06 00:16:32 2013 +0200 +++ b/nagslang/screens/area.py Fri Sep 06 00:17:22 2013 +0200 @@ -147,7 +147,7 @@ # else we're teleporting within the screen, and just the # position change is enough elif FireEvent.matches(ev): - bullet = Bullet(self.space, ev.source, ev.impulse, + bullet = Bullet(self.space, ev.source, ev.impulse, ev.damage, ev.source_collision_type) self._drawables.add(bullet) self.keys.handle_event(ev)