Clickable lights.
authorSimon Cross <hodgestar@gmail.com>
Tue, 6 Sep 2016 20:01:18 +0000 (22:01 +0200)
committerSimon Cross <hodgestar@gmail.com>
Tue, 6 Sep 2016 20:01:18 +0000 (22:01 +0200)
tabakrolletjie/lights.py
tabakrolletjie/scenes/day.py

index c5c72af0df43cb289f4528ea94fabb65c41b52ee..2590e310bc3247680ce13eef5f2bea7b1fdc7964 100644 (file)
@@ -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))
 
 
index 9d410c2a1172abba7e1c568eb4a52418eb887215..fc0ee9be5f098be41a63ad5a924c1ec544e9a502 100644 (file)
@@ -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