Restrict damage by light radius
authorNeil <neil@dip.sun.ac.za>
Fri, 9 Sep 2016 18:46:05 +0000 (20:46 +0200)
committerNeil <neil@dip.sun.ac.za>
Fri, 9 Sep 2016 19:06:46 +0000 (21:06 +0200)
tabakrolletjie/enemies.py

index 65bae00ea4af6b79e5eeba8f76984f8435b8eb58..a4ed7b73432e67f7ef54027b6d1674791c8debd0 100644 (file)
@@ -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: