Mercurial > nagslang
changeset 246:281c54cefe08
Added health to protagonist.
author | David Sharpe |
---|---|
date | Wed, 04 Sep 2013 22:46:29 +0200 |
parents | 21da1b41bbb6 |
children | 70d696b82399 |
files | nagslang/constants.py nagslang/protagonist.py nagslang/screens/area.py |
diffstat | 3 files changed, 30 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/nagslang/constants.py Wed Sep 04 22:26:36 2013 +0200 +++ b/nagslang/constants.py Wed Sep 04 22:46:29 2013 +0200 @@ -31,3 +31,7 @@ ZORDER_LOW = 1 ZORDER_MID = 2 ZORDER_HIGH = 3 + +WEREWOLF_SOAK_FACTOR = 10 +PROTAGONIST_HEALTH_MAX_LEVEL = 100 +PROTAGONIST_HEALTH_MIN_LEVEL = 0 \ No newline at end of file
--- a/nagslang/protagonist.py Wed Sep 04 22:26:36 2013 +0200 +++ b/nagslang/protagonist.py Wed Sep 04 22:46:29 2013 +0200 @@ -3,7 +3,9 @@ from pymunk.vec2d import Vec2d from nagslang import render -from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID +from nagslang.constants import COLLISION_TYPE_PLAYER, ZORDER_MID, \ + WEREWOLF_SOAK_FACTOR, PROTAGONIST_HEALTH_MIN_LEVEL, \ + PROTAGONIST_HEALTH_MAX_LEVEL from nagslang.game_object import GameObject, Physicser, make_body from nagslang.mutators import FLIP_H from nagslang.resources import resources @@ -50,6 +52,8 @@ super(Protagonist, self).__init__(physicser, renderer) self.zorder = ZORDER_MID + self.health_level = 100 + self.go_human() def _make_physics(self, space, position): @@ -229,3 +233,19 @@ if (dx, dy) == (0, 0): return self.physicser.apply_impulse((dx, dy)) + + def get_health_level(self): + return self.health_level + + def lose_health(self, amount): + if self.in_human_form(): + self.health_level -= amount + else: + self.health_level -= amount / WEREWOLF_SOAK_FACTOR + if self.health_level < PROTAGONIST_HEALTH_MIN_LEVEL: + self.health_level = PROTAGONIST_HEALTH_MIN_LEVEL + + def gain_health(self, amount): + self.health_level += amount + if self.health_level > PROTAGONIST_HEALTH_MAX_LEVEL: + self.health_level = PROTAGONIST_HEALTH_MAX_LEVEL \ No newline at end of file
--- a/nagslang/screens/area.py Wed Sep 04 22:26:36 2013 +0200 +++ b/nagslang/screens/area.py Wed Sep 04 22:46:29 2013 +0200 @@ -189,15 +189,15 @@ super(AreaScreen, self).tick(seconds) - def render_health_bar(self, surface, health_as_percentage=50, - health_type='human'): + def render_health_bar(self, surface): rect = pygame.Rect(50, 500, 110, 50) pygame.draw.rect(surface, pygame.color.THECOLORS['white'], rect, 0) - if health_type is 'human': + if self.protagonist.in_human_form(): health_colour = pygame.color.THECOLORS['red'] else: health_colour = pygame.color.THECOLORS['purple'] - rect = pygame.Rect(55, 505, health_as_percentage, 40) + rect = pygame.Rect(55, 505, self.protagonist.get_health_level(), 40) pygame.draw.rect(surface, health_colour, - rect, 0) \ No newline at end of file + rect, 0) + \ No newline at end of file