From 0183ccdfe81d661a768895326d45cb77b1c90fa6 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Tue, 6 Sep 2016 22:01:18 +0200 Subject: [PATCH] Clickable lights. --- tabakrolletjie/lights.py | 10 +++++----- tabakrolletjie/scenes/day.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index c5c72af..2590e31 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -75,11 +75,12 @@ class BaseLight(object): } def __init__(self, colour, position): - self.on = True - self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC) - self.fitting = pymunk.Circle(self.body, 5.0) self.colour = colour self.position = pymunk.Vec2d(position) + self.on = True + self.body = pymunk.Body(0, 0, pymunk.body.Body.STATIC) + self.fitting = pymunk.Circle(self.body, 10.0, self.position) + self.body.light = self @classmethod def load(cls, config): @@ -125,10 +126,9 @@ class BaseLight(object): surface.blit(subsurface, (0, 0), None) def render_fittings(self, surface): - centre = self.position + self.fitting.offset pygame.draw.circle( surface, (255, 255, 0), - pymunk.pygame_util.to_pygame(centre, surface), + pymunk.pygame_util.to_pygame(self.fitting.offset, surface), int(self.fitting.radius)) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 9d410c2..fc0ee9b 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -39,11 +39,11 @@ class DayScene(BaseScene): light.render_fittings(surface) def left_click(self, surfpos): - print "LEFT" pos = pymunk.pygame_util.from_pygame( surfpos, pygame.display.get_surface()) - print surfpos, pos - print self._space.point_query(pos, 1.0, CLICK_FILTER) + point_info = self._space.point_query_nearest(pos, 1.0, CLICK_FILTER) + if point_info is not None: + point_info.shape.body.light.toggle() def right_click(self, pos): pass -- 2.34.1