Mercurial > nagslang
comparison nagslang/enemies.py @ 305:ce11e1cae0ed
Enemies now die
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Fri, 06 Sep 2013 00:17:22 +0200 |
parents | e72025e9aa07 |
children | c2bbb1e70d6f |
comparison
equal
deleted
inserted
replaced
304:83477a7642b4 | 305:ce11e1cae0ed |
---|---|
23 """A base class for mobile enemies""" | 23 """A base class for mobile enemies""" |
24 | 24 |
25 def __init__(self, space, world, position): | 25 def __init__(self, space, world, position): |
26 self._setup_physics(space, position) | 26 self._setup_physics(space, position) |
27 self._setup_renderer() | 27 self._setup_renderer() |
28 self.health = 42 | |
28 | 29 |
29 super(Enemy, self).__init__( | 30 super(Enemy, self).__init__( |
30 self._physicser, self.renderer) | 31 self._physicser, self.renderer) |
31 self.zorder = ZORDER_MID | 32 self.zorder = ZORDER_MID |
32 self.world = world | 33 self.world = world |
44 raise NotImplementedError | 45 raise NotImplementedError |
45 | 46 |
46 @classmethod | 47 @classmethod |
47 def requires(cls): | 48 def requires(cls): |
48 return [("name", "string"), ("position", "coordinates")] | 49 return [("name", "string"), ("position", "coordinates")] |
50 | |
51 def lose_health(self, amount): | |
52 self.health -= amount | |
53 if self.health < 0: | |
54 self.world.kills += 1 | |
55 self.physicser.remove_from_space() | |
56 self.remove = True | |
49 | 57 |
50 | 58 |
51 class PatrollingAlien(Enemy): | 59 class PatrollingAlien(Enemy): |
52 is_moving = True # Always walking. | 60 is_moving = True # Always walking. |
53 | 61 |
127 self.set_direction(x_step, y_step) | 135 self.set_direction(x_step, y_step) |
128 super(PatrollingAlien, self).animate() | 136 super(PatrollingAlien, self).animate() |
129 | 137 |
130 def collide_with_protagonist(self, protagonist): | 138 def collide_with_protagonist(self, protagonist): |
131 protagonist.lose_health(15) | 139 protagonist.lose_health(15) |
140 | |
141 def hit(self, weapon): | |
142 self.lose_health(weapon.damage) | |
132 | 143 |
133 @classmethod | 144 @classmethod |
134 def requires(cls): | 145 def requires(cls): |
135 return [("name", "string"), ("position", "coordinates"), | 146 return [("name", "string"), ("position", "coordinates"), |
136 ("end_position", "coordinates")] | 147 ("end_position", "coordinates")] |