Add total power and damage.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 10:54:53 +0000 (12:54 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 10:54:53 +0000 (12:54 +0200)
tabakrolletjie/enemies.py
tabakrolletjie/lights.py
tabakrolletjie/rays.py
tabakrolletjie/scenes/night.py

index d40af93750b64be2592558d14e13c45242b2ba2d..eef2596e5300455ea7437d29642b27b9bdaabe02 100644 (file)
@@ -126,7 +126,7 @@ class Mould(pymunk.Body):
 
     def damage(self, light, space, moulds):
         """Take damage for light, adjusted for resistances."""
-        self._health -= 3
+        self._health -= light.base_damage()
         if self._health <= 0 and self._age <= 120:
             # We die of damage
             space.remove(self, self._shape)
index 03adf387cb2fb299ac57bc2942d7870532c31719..8b688f71907588608f698084615eb8f4b6c37e8f 100644 (file)
@@ -1,6 +1,8 @@
 """ May it be a light for you in dark places, when all other lights go out.
 """
 
+import math
+
 import pymunk
 import pymunk.pygame_util
 import pygame.display
@@ -83,6 +85,9 @@ class LightManager(object):
             if light.on and light.ray_manager.reaches(shape.body.position)
         ]
 
+    def total_power_usage(self):
+        return sum(light.power_usage() for light in self._lights)
+
     def render_light(self, surface):
         for light in self._lights:
             light.render_light(surface)
@@ -213,6 +218,16 @@ class BaseLight(object):
         rx, ry = self.ray_manager.pygame_position(surface)
         surface.blit(self.fitting_image(), (rx - 24, ry - 24), None, 0)
 
+    def power_usage(self):
+        if not self.on:
+            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
+
+    def base_damage(self):
+        return 5 * self.intensity
+
     def toggle(self):
         self.colour_pos += 1
         if self.colour_pos >= len(self.colour_cycle):
index 7c8b5beab712c0fe756afbb7645afc92fc3b563c..b4142a3e6694f8ecaeb4f67264a4bb270ca7a025 100644 (file)
@@ -156,6 +156,12 @@ class RayPolyManager(object):
         self._end = self._direction.rotated(-spread)
         self._poly_cache = None
 
+    @property
+    def spread(self):
+        if not self._direction:
+            return 2 * math.pi
+        return math.fabs(self._start.get_angle_between(self._end))
+
     def _set_angle_limits(self, direction, spread):
         if direction is None or spread is None:
             self._direction = None
index d8f0e1a53144d9993734644cb3d5bc65d37abce7..ff982139ac114df3147f134e8e6988e2a7b5fc69 100644 (file)
@@ -66,6 +66,7 @@ class NightScene(BaseScene):
     def tick(self, gamestate):
         self._mould.tick(gamestate, self._space, self._lights)
         self._lights.tick()
+        print "Power usage: ", self._lights.total_power_usage()
 
     def exit(self, gamestate):
         turnip_data = [turnip.serialize() for turnip in self._turnips]