Add todo items
[tabakrolletjie.git] / tabakrolletjie / lights.py
index 1eaba7c8e92ee3804026383fdc3ece6c06dfe203..7b2c26380c9800ded9540fcb281766d87903b679 100644 (file)
@@ -9,6 +9,7 @@ import pygame.display
 import pygame.draw
 import pygame.locals as pgl
 import pygame.rect
+import pygame.transform
 
 from .constants import LIGHT_CATEGORY, FITTINGS_CATEGORY, COLOURS
 from .rays import RayPolyManager
@@ -214,8 +215,8 @@ class BaseLight(object):
 
             if ncolour == 1:
                 self._fitting_image = loader.load_image(
-                "48", self.FITTING_IMG,
-                transform=Multiply(colour=fitting_colours[0]))
+                    "48", self.FITTING_IMG,
+                    transform=Multiply(colour=fitting_colours[0]))
             else:
                 if self._colour_mult_image is None:
                     self._colour_mult_image = pygame.surface.Surface((48, 48))
@@ -224,8 +225,8 @@ class BaseLight(object):
                         sector = loader.load_image(
                             "48", "light_mask_%d_%d.png" % (ncolour, i + 1),
                             transform=Multiply(colour=fitting_colours[i]))
-                        self._colour_mult_image.blit(sector, (0,0), None, 0)
-                    
+                        self._colour_mult_image.blit(sector, (0, 0), None, 0)
+
                 self._fitting_image = loader.load_image(
                     "48", self.FITTING_IMG,
                     transform=MultiplyImage(image=self._colour_mult_image))
@@ -244,7 +245,7 @@ class BaseLight(object):
             return 0.0
         area = math.pi * (self.ray_manager.max_radius ** 2)  # radius
         area = area * (self.ray_manager.spread / (2 * math.pi))  # spread
-        return 5 * area * self.intensity
+        return 5 * area * self.intensity / 6400  # 80x80 unit area
 
     def base_damage(self):
         return 5 * self.intensity
@@ -258,7 +259,6 @@ class BaseLight(object):
         else:
             self.colour = self.colour_cycle[self.colour_pos]
             self.on = True
-        self.invalidate_fitting_image()
 
     def tick(self):
         pass
@@ -312,6 +312,17 @@ class SpotLight(BaseLight):
         self.angular_velocity = kw.pop("angular_velocity", None)
         super(SpotLight, self).__init__(**kw)
 
+    def fitting_image(self):
+        fitting_image = super(SpotLight, self).fitting_image()
+        rot_fitting_image = pygame.transform.rotozoom(fitting_image, self.ray_manager.direction - 90, 1)
+
+        rot_rect = fitting_image.get_rect().copy()
+        rot_rect.center = rot_fitting_image.get_rect().center
+        rot_fitting_image = rot_fitting_image.subsurface(rot_rect).copy()
+        
+        return rot_fitting_image
+        
+
     def tick(self):
         if self.angular_velocity:
             self.ray_manager.direction -= self.angular_velocity