From dcf7ce331cce842edfde44a3f48aa4c99d66097a Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 9 Sep 2016 20:46:05 +0200 Subject: [PATCH] Restrict damage by light radius --- tabakrolletjie/enemies.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tabakrolletjie/enemies.py b/tabakrolletjie/enemies.py index 65bae00..a4ed7b7 100644 --- a/tabakrolletjie/enemies.py +++ b/tabakrolletjie/enemies.py @@ -8,8 +8,6 @@ import pygame.draw import pygame.surface import pygame.display -import pygame.locals as pgl - from .constants import (SCREEN_SIZE, MOULD_CATEGORY, OBSTACLE_CATEGORY, TURNIP_CATEGORY) from .loader import loader @@ -126,8 +124,13 @@ class Mould(pymunk.Body): query[0].shape.body.turnip.eaten = True return refresh - def damage(self, light_color, intensity, space, moulds): + def damage(self, light, space, moulds): """Take damage for light, adjusted for resistances.""" + distance = light.position.get_distance(self.position) + if distance < (light.radius_limits[0] or 0.0): + return False + if distance > (light.radius_limits[1] or 50.0): + return False self._health -= 3 if self._health <= 0 and self._age <= 120: # We die of damage @@ -140,7 +143,7 @@ class Mould(pymunk.Body): class Boyd(object): def __init__(self, gamestate, space): - seed = Mould(gamestate, space, (350, 370)) + seed = Mould(gamestate, space, (275, 300)) self._moulds = [seed] self._image = pygame.surface.Surface(SCREEN_SIZE) self._image = self._image.convert_alpha(pygame.display.get_surface()) @@ -168,7 +171,7 @@ class Boyd(object): lit_by = lights.light_query(mould._shape) for light in lit_by: # Todo: extract colour and intensity from light - if mould.damage(None, None, space, self._moulds): + if mould.damage(light, space, self._moulds): redraw = True break # we only die once if redraw: -- 2.34.1