From: Simon Cross Date: Sat, 10 Sep 2016 19:37:32 +0000 (+0200) Subject: Don't allow placing lights on turnips, obstacles or other lights. X-Git-Tag: tabakrolletjie-v1.0.0~50 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=4b40709e4dcc9c9924a93f6c4b5cfd8217c4d2af;p=tabakrolletjie.git Don't allow placing lights on turnips, obstacles or other lights. --- diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 8ef1265..2736509 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -11,7 +11,9 @@ import pygame.locals as pgl import pygame.rect import pygame.transform -from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY, COLOURS +from .constants import ( + LIGHT_CATEGORY, FITTINGS_CATEGORY, OBSTACLE_CATEGORY, TURNIP_CATEGORY, + COLOURS) from .rays import RayPolyManager from .utils import DetailedTimer from .loader import loader @@ -29,6 +31,16 @@ FITTINGS_FILTER = pymunk.ShapeFilter( # Just match lights, nothing else LIT_BY_FILTER = pymunk.ShapeFilter(mask=LIGHT_CATEGORY) +SPACE_FOR_LIGHT_FILTER = pymunk.ShapeFilter( + mask=FITTINGS_CATEGORY | OBSTACLE_CATEGORY | TURNIP_CATEGORY) + + +def check_space_for_light(space, pos, max_distance): + point_info = space.point_query_nearest( + pos, max_distance, SPACE_FOR_LIGHT_FILTER) + if point_info is not None: + return True + return False class LightManager(object): diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index cc7a32e..be86425 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -11,7 +11,7 @@ import pymunk.pygame_util from .base import BaseScene from ..battery import BatteryManager -from ..lights import LightManager, light_fitting_by_type +from ..lights import LightManager, light_fitting_by_type, check_space_for_light from ..infobar import InfoBar from ..obstacles import ObstacleManager from ..events import SceneChangeEvent @@ -21,7 +21,7 @@ from ..transforms import Overlay, Alpha, ColourWedges from ..constants import SCREEN_SIZE, FONTS, FPS, NIGHT_HOURS_PER_TICK, DEBUG from ..widgets import ImageButton -from ..turnip import Turnip, TurnipInvalidPosition, check_turnips +from ..turnip import Turnip, TurnipInvalidPosition class DayScene(BaseScene): @@ -215,11 +215,8 @@ class DayScene(BaseScene): if gamestate.seeds > cost: pos = pymunk.pygame_util.from_pygame( ev.pos, pygame.display.get_surface()) - # 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): + # Bail if we're too close to an existing light, obstacle or turnip + if check_space_for_light(self._space, pos, max_distance=25): return gamestate.seeds -= cost cfg["position"] = pos diff --git a/tabakrolletjie/turnip.py b/tabakrolletjie/turnip.py index 72705fc..b67196a 100644 --- a/tabakrolletjie/turnip.py +++ b/tabakrolletjie/turnip.py @@ -14,14 +14,6 @@ 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