Lights can now be turned on and off at night.
authorSimon Cross <hodgestar@gmail.com>
Tue, 6 Sep 2016 20:33:35 +0000 (22:33 +0200)
committerSimon Cross <hodgestar@gmail.com>
Tue, 6 Sep 2016 20:33:35 +0000 (22:33 +0200)
tabakrolletjie/lights.py
tabakrolletjie/scenes/day.py
tabakrolletjie/scenes/night.py

index 54da531db68de8df8d3d7e9ca7333c10b4e2aa5f..ff7035abb0cfe09ceafa09ef344907b29114e5d5 100644 (file)
@@ -74,7 +74,12 @@ class LightManager(object):
         for light in self._lights:
             light.add(self._space)
 
-    def nearest(self, pos, surfpos=False, max_distance=1.0):
+    def toggle_nearest(self, *args, **kw):
+        light = self.nearest(*args, **kw)
+        if light:
+            light.toggle()
+
+    def nearest(self, pos, surfpos=True, max_distance=1.0):
         if surfpos:
             surface = pygame.display.get_surface()
             pos = pymunk.pygame_util.from_pygame(pos, surface)
index 26440efbc142269d7f91561d2da051772f727327..816a8593cdd91ab0d24277301d6540177bb26a95 100644 (file)
@@ -25,14 +25,6 @@ class DayScene(BaseScene):
         self._obstacles.render(surface)
         self._lights.render_fittings(surface)
 
-    def left_click(self, pos):
-        light = self._lights.nearest(pos, surfpos=True)
-        if light:
-            light.toggle()
-
-    def right_click(self, pos):
-        pass
-
     def event(self, ev, gamestate):
         if ev.type == pgl.KEYDOWN:
             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
@@ -40,9 +32,7 @@ class DayScene(BaseScene):
                 SceneChangeEvent.post(scene=MenuScene())
         elif ev.type == pgl.MOUSEBUTTONDOWN:
             if ev.button == 1:
-                self.left_click(ev.pos)
-            elif ev.button == 3:
-                self.right_click(ev.pos)
+                self._lights.toggle_nearest(ev.pos)
 
     @debug_timer("day.tick")
     def tick(self, gamestate):
index c558fc0fcb429091cf2e3d7c11004230905cad56..6c30603b713303ebf3635228426cd461e3d7b2bb 100644 (file)
@@ -32,9 +32,9 @@ class NightScene(BaseScene):
             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
                 from .menu import MenuScene
                 SceneChangeEvent.post(scene=MenuScene())
-            elif ev.key == pgl.K_t:
-                for light in self._lights:
-                    light.toggle()
+        elif ev.type == pgl.MOUSEBUTTONDOWN:
+            if ev.button == 1:
+                self._lights.toggle_nearest(ev.pos)
 
     @debug_timer("night.tick")
     def tick(self, gamestate):