Hacky demonstration of changing angle limits.
authorSimon Cross <hodgestar@gmail.com>
Wed, 7 Sep 2016 21:30:04 +0000 (23:30 +0200)
committerSimon Cross <hodgestar@gmail.com>
Wed, 7 Sep 2016 21:30:04 +0000 (23:30 +0200)
tabakrolletjie/lights.py

index c143b98862326dc385658b53998934d45b7ff179..22f43586e44343c23c7481dc46df02098e7a3d1d 100644 (file)
@@ -76,6 +76,10 @@ class LightManager(object):
         for light in self._lights:
             light.render_fitting(surface)
 
+    def tick(self):
+        for light in self._lights:
+            light.tick()
+
 
 class BaseLight(object):
     """ Common light functionality. """
@@ -119,6 +123,7 @@ class BaseLight(object):
         if self.body.space is not None:
             space.remove(self.body, *self.body.shapes)
         self.ray_manager.generate_rays(space, self.position)
+        self.ray_manager.set_angle_limits(self.angle_limits)
         ray_shapes = self.ray_manager.polys()
         space.add(self.body, self.fitting, *ray_shapes)
 
@@ -188,9 +193,21 @@ class BaseLight(object):
             pymunk.pygame_util.to_pygame(self.fitting.offset, surface),
             int(self.fitting.radius))
 
+    def tick(self):
+        pass
+
 
 class SpotLight(BaseLight):
     def __init__(self, **kw):
         kw.pop("direction", None)
         kw.pop("spread", None)
+        self.angular_velocity = kw.pop("angular_velocity", None)
         super(SpotLight, self).__init__(**kw)
+
+    def tick(self):
+        if self.angular_velocity:
+            start, end = self.angle_limits
+            start = (start + self.angular_velocity) % 360.0
+            end = (end + self.angular_velocity) % 360.0
+            self.angle_limits = (start, end)
+            self.ray_manager.set_angle_limits(self.angle_limits)