Changeset 246:281c54cefe08 for nagslang


Ignore:
Timestamp:
Sep 4, 2013, 8:46:29 PM (7 years ago)
Author:
David Sharpe
Branch:
default
Message:

Added health to protagonist.

Location:
nagslang
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r186 r246  
    3232ZORDER_MID = 2
    3333ZORDER_HIGH = 3
     34
     35WEREWOLF_SOAK_FACTOR = 10
     36PROTAGONIST_HEALTH_MAX_LEVEL = 100
     37PROTAGONIST_HEALTH_MIN_LEVEL = 0
  • nagslang/protagonist.py

    r230 r246  
    44
    55from nagslang import render
    6 from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID
     6from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID, \
     7    WEREWOLF_SOAK_FACTOR, PROTAGONIST_HEALTH_MIN_LEVEL, \
     8    PROTAGONIST_HEALTH_MAX_LEVEL
    79from nagslang.game_object import GameObject, Physicser, make_body
    810from nagslang.mutators import FLIP_H
     
    5052        super(Protagonist, self).__init__(physicser, renderer)
    5153        self.zorder = ZORDER_MID
     54
     55        self.health_level = 100
    5256
    5357        self.go_human()
     
    230234            return
    231235        self.physicser.apply_impulse((dx, dy))
     236
     237    def get_health_level(self):
     238        return self.health_level
     239
     240    def lose_health(self, amount):
     241        if self.in_human_form():
     242            self.health_level -= amount
     243        else:
     244            self.health_level -= amount / WEREWOLF_SOAK_FACTOR
     245        if self.health_level < PROTAGONIST_HEALTH_MIN_LEVEL:
     246            self.health_level = PROTAGONIST_HEALTH_MIN_LEVEL
     247
     248    def gain_health(self, amount):
     249        self.health_level += amount
     250        if self.health_level > PROTAGONIST_HEALTH_MAX_LEVEL:
     251            self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL
  • nagslang/screens/area.py

    r244 r246  
    190190        super(AreaScreen, self).tick(seconds)
    191191
    192     def render_health_bar(self, surface, health_as_percentage=50,
    193                          health_type='human'):
     192    def render_health_bar(self, surface):
    194193        rect = pygame.Rect(50, 500, 110, 50)
    195194        pygame.draw.rect(surface,  pygame.color.THECOLORS['white'],
    196195                         rect, 0)
    197         if health_type is 'human':
     196        if self.protagonist.in_human_form():
    198197            health_colour = pygame.color.THECOLORS['red']
    199198        else:
    200199            health_colour = pygame.color.THECOLORS['purple']
    201         rect = pygame.Rect(55, 505, health_as_percentage, 40)
     200        rect = pygame.Rect(55, 505, self.protagonist.get_health_level(), 40)
    202201        pygame.draw.rect(surface,  health_colour,
    203202                         rect, 0)
     203       
Note: See TracChangeset for help on using the changeset viewer.