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)
""" 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
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)
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):
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
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]