Tweak the colour of night.
[tabakrolletjie.git] / tabakrolletjie / lights.py
index 92b66e0a8d4b91907fdec632724e00b0ffa9fba8..81740d88fd2003603c3332323900d120f3f5d283 100644 (file)
@@ -2,6 +2,8 @@
 """
 
 import pymunk
+import pymunk.pygame_util
+import pygame.draw
 
 
 class BaseLight(object):
@@ -12,10 +14,11 @@ class BaseLight(object):
         self.colour = colour
         self.position = position
 
-    def add_to_space(self, space):
-        space.remove(self.body, **self.body.shapes())
+    def add(self, space):
+        if self.body.space is not None:
+            space.remove(self.body, *self.body.shapes)
         shapes = self.determine_ray_polys(space)
-        space.add(self.body, **shapes)
+        space.add(self.body, *shapes)
 
     def determine_ray_polys(self, space):
         raise NotImplementedError(
@@ -38,6 +41,18 @@ class SpotLight(BaseLight):
         self.direction = direction
         self.spread = spread
 
+    def determine_ray_polys(self, space):
+        x, y = self.position
+        return [pymunk.Poly(self.body, [
+            self.position, [x + 50, y], [x, y + 50]])]
+
+    def render(self, surface):
+        for shape in self.body.shapes:
+            pygame_poly = [
+                pymunk.pygame_util.to_pygame(v, surface) for v in
+                shape.get_vertices()]
+            pygame.draw.polygon(surface, (255, 255, 255), pygame_poly)
+
 
 class Lamp(BaseLight):
     def __init__(self, colour="white", position=None, radius=100.0):