Use pulsating lamp images.
[tabakrolletjie.git] / tabakrolletjie / lights.py
index 498c0b09c644c5de9bda9a2be4a3dabfb7c7a7ef..cda60022a5d5aa227d7a9401ad119ca31ff2ba67 100644 (file)
@@ -59,6 +59,10 @@ class LightManager(object):
         self._lights.append(light)
         light.add(self._space)
 
+    def remove_light(self, light):
+        self._lights.remove(light)
+        light.remove(self._space)
+
     def battery_dead(self):
         self._battery_dead = True
         for light in self._lights:
@@ -146,7 +150,8 @@ class BaseLight(object):
 
     def __init__(
             self, colours, position, intensity=1.0, radius_limits=None,
-            direction=None, spread=None, on=True, start_colour=None):
+            direction=None, spread=None, on=True, start_colour=None,
+            bounding_radius=None):
         self.colour_cycle = colours
         self.colour_pos = 0
         self.colour = colours[0]
@@ -161,7 +166,8 @@ class BaseLight(object):
         self.body.light = self
         self.ray_manager = self.RAY_MANAGER(
             self.body, position, ray_filter=LIGHT_FILTER,
-            radius_limits=radius_limits, direction=direction, spread=spread)
+            radius_limits=radius_limits, direction=direction, spread=spread,
+            bounding_radius=bounding_radius)
         self.fitting = pymunk.Circle(
             self.body, self.FITTING_RADIUS, self.ray_manager.position)
         self.fitting.filter = FITTINGS_FILTER
@@ -205,6 +211,10 @@ class BaseLight(object):
         self.ray_manager.set_space(space)
         self.ray_manager.update_shapes()
 
+    def remove(self, space):
+        if self.body.space is not None:
+            space.remove(self.body, *self.body.shapes)
+
     def _cached_surface(self, name, surface):
         surf = self._surface_cache.get(name)
         if surf is None:
@@ -306,7 +316,7 @@ class Lamp(BaseLight):
 
 class PulsatingLamp(BaseLight):
 
-    FITTING_IMG = "lamp.png"
+    FITTING_IMG = "pulsatinglamp.png"
     DEFAULT_PULSE_RANGE = (20, 100)
     DEFAULT_PULSE_VELOCITY = 2
     DEFAULT_INTENSITY_RANGE = (0.0, 0.9)
@@ -320,7 +330,8 @@ class PulsatingLamp(BaseLight):
             "intensity_range", self.DEFAULT_INTENSITY_RANGE)
         self.intensity_velocity = kw.pop(
             "intensity_velocity", self.DEFAULT_INTENSITY_VELOCITY)
-        super(PulsatingLamp, self).__init__(**kw)
+        super(PulsatingLamp, self).__init__(
+            bounding_radius=self.pulse_range[1], **kw)
 
     def serialize(self):
         result = super(PulsatingLamp, self).serialize()