Changeset 258:083053422a84


Ignore:
Timestamp:
Sep 4, 2013, 10:05:17 PM (7 years ago)
Author:
David Sharpe
Branch:
default
rebase_source:
1935c06494a59481c720e77e157f24a0f2bd323c
Message:

Added collision damage with enemies.

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/enemies.py

    r235 r258  
    127127        super(PatrollingAlien, self).animate()
    128128
     129    def collide_with_protagonist(self):
     130        return 5
     131
    129132    @classmethod
    130133    def requires(cls):
  • nagslang/screens/area.py

    r257 r258  
    55import pymunk.pygame_util
    66
    7 from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS
     7from nagslang.constants import COLLISION_TYPE_PLAYER, CALLBACK_COLLIDERS, \
     8    COLLISION_TYPE_ENEMY
    89from nagslang.events import ScreenChange, DoorEvent
    910from nagslang.level import Level
     
    8586        gobj = arbiter.shapes[1].physicser.game_object
    8687        result = gobj.collide_with_protagonist(self.protagonist)
     88        if arbiter.shapes[1].collision_type == COLLISION_TYPE_ENEMY:
     89            self.protagonist.lose_health(15)
    8790        # The collision handler must return `True` or `False`. We don't want to
    8891        # accidentally reject collisions from handlers that return `None`, so
     
    190193        super(AreaScreen, self).tick(seconds)
    191194
    192     def render_health_bar(self, surface):
     195    def render_health_bar(self, surface, damage_experienced=None):
    193196        rect = pygame.Rect(50, 500, 110, 50)
     197        if damage_experienced:
     198            health_box_colour = pygame.color.THECOLORS['red']
     199        else:
     200            health_box_colour = pygame.color.THECOLORS['white']
    194201        pygame.draw.rect(surface,  health_box_colour, rect, 0)
    195202        if self.protagonist.in_human_form():
Note: See TracChangeset for help on using the changeset viewer.