Mercurial > nagslang
changeset 258:083053422a84
Added collision damage with enemies.
author | David Sharpe |
---|---|
date | Thu, 05 Sep 2013 00:05:17 +0200 |
parents | c00022002c63 |
children | f23be1013c94 |
files | nagslang/enemies.py nagslang/screens/area.py |
diffstat | 2 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/nagslang/enemies.py Thu Sep 05 00:08:58 2013 +0200 +++ b/nagslang/enemies.py Thu Sep 05 00:05:17 2013 +0200 @@ -126,6 +126,9 @@ self.set_direction(x_step, y_step) super(PatrollingAlien, self).animate() + def collide_with_protagonist(self): + return 5 + @classmethod def requires(cls): return [("name", "string"), ("position", "coordinates"),
--- a/nagslang/screens/area.py Thu Sep 05 00:08:58 2013 +0200 +++ b/nagslang/screens/area.py Thu Sep 05 00:05:17 2013 +0200 @@ -4,7 +4,8 @@ import pymunk import pymunk.pygame_util -from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS +from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS, \ + COLLISION_TYPE_ENEMY from nagslang.events import ScreenChange, DoorEvent from nagslang.level import Level from nagslang.protagonist import Protagonist @@ -84,6 +85,8 @@ def _collision_pre_solve_handler(self, space, arbiter): gobj = arbiter.shapes[1].physicser.game_object result = gobj.collide_with_protagonist(self.protagonist) + if arbiter.shapes[1].collision_type == COLLISION_TYPE_ENEMY: + self.protagonist.lose_health(15) # The collision handler must return `True` or `False`. We don't want to # accidentally reject collisions from handlers that return `None`, so # we explicitly check for `False` and treate everything else as `True`. @@ -189,8 +192,12 @@ super(AreaScreen, self).tick(seconds) - def render_health_bar(self, surface): + def render_health_bar(self, surface, damage_experienced=None): rect = pygame.Rect(50, 500, 110, 50) + if damage_experienced: + health_box_colour = pygame.color.THECOLORS['red'] + else: + health_box_colour = pygame.color.THECOLORS['white'] pygame.draw.rect(surface, health_box_colour, rect, 0) if self.protagonist.in_human_form(): health_colour = pygame.color.THECOLORS['red']