Limit how close lights can be placed to each other
authorNeil <neil@dip.sun.ac.za>
Fri, 9 Sep 2016 21:46:58 +0000 (23:46 +0200)
committerNeil <neil@dip.sun.ac.za>
Fri, 9 Sep 2016 21:46:58 +0000 (23:46 +0200)
tabakrolletjie/scenes/day.py

index 7860c87b44e4db2d09c7c11549215648a0ab0acb..1c518c526514a0ea8871dedf5e2d87e4f831caf4 100644 (file)
@@ -100,10 +100,13 @@ class DayScene(BaseScene):
 
     def _place_spotlight(self, gamestate, colour, ev):
         if self._seeds > 5:
-            self._seeds -= 5
-            self._update_toolbar(gamestate)
             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
+            self._seeds -= 5
+            self._update_toolbar(gamestate)
             cfg = {
                 "type": "spotlight",
                 "colour": colour,