Check that we're not placing lights on top of turnips
authorNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 17:20:28 +0000 (19:20 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 17:20:35 +0000 (19:20 +0200)
tabakrolletjie/scenes/day.py
tabakrolletjie/turnip.py

index 4c3cbfe9759c01458be1c1bcb307f4d1ca74221c..f0db831da1cd068fece25d289a98266c3c3e954a 100644 (file)
@@ -21,7 +21,7 @@ from ..transforms import Overlay, Alpha, ColourWedges
 
 from ..constants import SCREEN_SIZE, FONTS, DEBUG
 from ..widgets import ImageButton
-from ..turnip import Turnip, TurnipInvalidPosition
+from ..turnip import Turnip, TurnipInvalidPosition, check_turnips
 
 
 class DayScene(BaseScene):
@@ -216,6 +216,9 @@ class DayScene(BaseScene):
             # Bail if we're too close to an existing light
             if self._lights.nearest(pos, max_distance=25):
                 return
+            # Also check turnips
+            if check_turnips(self._space, pos, max_distance=25):
+                return
             gamestate.seeds -= cost
             cfg["position"] = pos
             cfg["colours"] = colours
index b67196a525da4d00d19c024aee3880399194a49c..72705fccdf7aa18e3548357ffc14954e0d9a41a8 100644 (file)
@@ -14,6 +14,14 @@ TURNIP_FILTER = pymunk.ShapeFilter(
     categories=TURNIP_CATEGORY)
 
 
+def check_turnips(space, pos, max_distance):
+    point_info = space.point_query_nearest(
+        pos, max_distance, pymunk.ShapeFilter(mask=TURNIP_CATEGORY))
+    if point_info is not None:
+        return True
+    return False
+
+
 class TurnipInvalidPosition(Exception):
     pass