From: Neil Date: Tue, 6 Sep 2016 21:58:06 +0000 (+0200) Subject: Simple light damage using lit_by X-Git-Tag: tabakrolletjie-v1.0.0~213 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=53356dd6cda09226e2d46ddf94d00283412577b5;p=tabakrolletjie.git Simple light damage using lit_by --- diff --git a/tabakrolletjie/enemies.py b/tabakrolletjie/enemies.py index f668f1a..fd7a6d4 100644 --- a/tabakrolletjie/enemies.py +++ b/tabakrolletjie/enemies.py @@ -30,6 +30,7 @@ class Mould(pymunk.Body): self._resistances = {} self._age = 0 self._img = None + self._health = 500 def pygame_pos(self, surface): """Convert to pygame coordinates and offset position so @@ -49,6 +50,10 @@ class Mould(pymunk.Body): """Grow and / or Die""" self._age += 1 + # we regain a health every tick, so we heal in the dark + if self._health < 100: + self._health += 1 + refresh = False if (self._age % 15) == 0 and len(moulds) < 1000: @@ -78,6 +83,7 @@ class Mould(pymunk.Body): spawn = False if spawn: child = Mould(gamestate, space, pos) + child._health = self._health moulds.append(child) refresh = True @@ -88,14 +94,21 @@ class Mould(pymunk.Body): refresh = True return refresh - def damage(self, light_color, intensity): + def damage(self, light_color, intensity, space, moulds): """Take damage for light, adjusted for resistances.""" + self._health -= 3 + if self._health <= 0 and self._age <= 120: + # We die of damage + space.remove(self, self._shape) + moulds.remove(self) + return True + return False class Boyd(object): def __init__(self, gamestate, space): - seed = Mould(gamestate, space, (350, 350)) + seed = Mould(gamestate, space, (350, 370)) self._moulds = [seed] self._image = pygame.surface.Surface(SCREEN_SIZE) self._image.convert_alpha(pygame.display.get_surface()) @@ -103,11 +116,17 @@ class Boyd(object): self._image.blit(seed.get_image(), seed.pygame_pos(self._image), None, pgl.BLEND_RGBA_ADD) - def tick(self, gamestate, space): + def tick(self, gamestate, space, lights): redraw = False + # Handle spawn events for mould in self._moulds[:]: + # Handle updates if mould.tick(gamestate, space, self._moulds): redraw = True + # Check for damage + if lights.lit_by(mould.position): + if mould.damage(None, None, space, self._moulds): + redraw = True if redraw: self._image.fill((0, 0, 0, 0)) for mould in self._moulds: diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 3504461..b4e19e8 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -39,4 +39,4 @@ class NightScene(BaseScene): @debug_timer("night.tick") def tick(self, gamestate): - self._mould.tick(gamestate, self._space) + self._mould.tick(gamestate, self._space, self._lights)