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)
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):
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):
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):