From 42c64c1b6e9bf55aa5bcfd3a83c9373084b4efa3 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 10 Sep 2016 19:20:28 +0200 Subject: [PATCH] Check that we're not placing lights on top of turnips --- tabakrolletjie/scenes/day.py | 5 ++++- tabakrolletjie/turnip.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 4c3cbfe..f0db831 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -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 diff --git a/tabakrolletjie/turnip.py b/tabakrolletjie/turnip.py index b67196a..72705fc 100644 --- a/tabakrolletjie/turnip.py +++ b/tabakrolletjie/turnip.py @@ -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 -- 2.34.1