# HG changeset patch # User David Sharpe # Date 1378332317 -7200 # Node ID 083053422a841dd8702f427f7432923ef3a98bb7 # Parent c00022002c633c5cab9ab3ad81e52f63db3899f1 Added collision damage with enemies. diff -r c00022002c63 -r 083053422a84 nagslang/enemies.py --- 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"), diff -r c00022002c63 -r 083053422a84 nagslang/screens/area.py --- 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']