From: Simon Cross Date: Tue, 6 Sep 2016 20:33:35 +0000 (+0200) Subject: Lights can now be turned on and off at night. X-Git-Tag: tabakrolletjie-v1.0.0~216 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=04c5963c582d6ba364f8fc30899dfc817f419e82;p=tabakrolletjie.git Lights can now be turned on and off at night. --- diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 54da531..ff7035a 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -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) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 26440ef..816a859 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -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): diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index c558fc0..6c30603 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -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):