From a2c09130986d18095773c96b9dc797f3b3eb542d Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 12:54:53 +0200 Subject: [PATCH] Add total power and damage. --- tabakrolletjie/enemies.py | 2 +- tabakrolletjie/lights.py | 15 +++++++++++++++ tabakrolletjie/rays.py | 6 ++++++ tabakrolletjie/scenes/night.py | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tabakrolletjie/enemies.py b/tabakrolletjie/enemies.py index d40af93..eef2596 100644 --- a/tabakrolletjie/enemies.py +++ b/tabakrolletjie/enemies.py @@ -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) diff --git a/tabakrolletjie/lights.py b/tabakrolletjie/lights.py index 03adf38..8b688f7 100644 --- a/tabakrolletjie/lights.py +++ b/tabakrolletjie/lights.py @@ -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): diff --git a/tabakrolletjie/rays.py b/tabakrolletjie/rays.py index 7c8b5be..b4142a3 100644 --- a/tabakrolletjie/rays.py +++ b/tabakrolletjie/rays.py @@ -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 diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index d8f0e1a..ff98213 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -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] -- 2.34.1