From 923e068edb27b9b6d35359e496668038a1db6fa4 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sat, 10 Sep 2016 21:18:08 +0200 Subject: [PATCH] Display power usage per hour. --- tabakrolletjie/constants.py | 4 ++-- tabakrolletjie/infobar.py | 2 +- tabakrolletjie/scenes/day.py | 6 ++++-- tabakrolletjie/scenes/night.py | 10 ++++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tabakrolletjie/constants.py b/tabakrolletjie/constants.py index 0ea58f5..63e13dd 100644 --- a/tabakrolletjie/constants.py +++ b/tabakrolletjie/constants.py @@ -17,10 +17,10 @@ SCREEN_SIZE = (1024, 704) # Frame per second FPS = 30 -# Night length in ticks +# Night length in ticks and hours NIGHT_LENGTH = 1500 -# Night length in hours NIGHT_LENGTH_HOURS = 12 +NIGHT_HOURS_PER_TICK = float(NIGHT_LENGTH_HOURS) / NIGHT_LENGTH # Pymunk categories OBSTACLE_CATEGORY = 1 << 0 diff --git a/tabakrolletjie/infobar.py b/tabakrolletjie/infobar.py index ac9f1a9..6697892 100644 --- a/tabakrolletjie/infobar.py +++ b/tabakrolletjie/infobar.py @@ -26,7 +26,7 @@ class InfoBar(object): "{gamestate.seeds} seeds", "{scene.turnip_count} plants", "battery {battery.current}/{battery.max}", - "power usage {scene.power_usage}" + "power usage {scene.power_usage}/h" ]) self._font = loader.load_font(FONTS['sans'], size=20) self._text = None diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 1e65fe1..cc7a32e 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -19,7 +19,7 @@ from ..utils import debug_timer, shadowed_text from ..loader import loader from ..transforms import Overlay, Alpha, ColourWedges -from ..constants import SCREEN_SIZE, FONTS, DEBUG +from ..constants import SCREEN_SIZE, FONTS, FPS, NIGHT_HOURS_PER_TICK, DEBUG from ..widgets import ImageButton from ..turnip import Turnip, TurnipInvalidPosition, check_turnips @@ -138,7 +138,9 @@ class DayScene(BaseScene): @property def power_usage(self): - return int(self._lights.total_power_usage()) + power = self._lights.total_power_usage() + power = power / (FPS * NIGHT_HOURS_PER_TICK) + return int(round(power)) @debug_timer("day.render") def render(self, surface, gamestate): diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index e4cc733..580d140 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -18,13 +18,13 @@ from ..transforms import Overlay from ..turnip import Turnip from ..widgets import ImageButton from ..constants import ( - NIGHT_LENGTH, NIGHT_LENGTH_HOURS, DEBUG, FONTS, SCREEN_SIZE, FPS) + NIGHT_LENGTH, NIGHT_HOURS_PER_TICK, DEBUG, FONTS, + SCREEN_SIZE, FPS) class NightScene(BaseScene): DARKNESS = Overlay(colour=(0, 0, 0, 150)) - HOURS_PER_TICK = float(NIGHT_LENGTH_HOURS) / NIGHT_LENGTH def enter(self, gamestate): self._space = pymunk.Space() @@ -69,11 +69,13 @@ class NightScene(BaseScene): @property def power_usage(self): - return int(self._lights.total_power_usage()) + power = self._lights.total_power_usage() + power = power / (FPS * NIGHT_HOURS_PER_TICK) + return int(round(power)) def remaining_hours(self): return int(round( - (NIGHT_LENGTH - self._total_ticks) * self.HOURS_PER_TICK)) + (NIGHT_LENGTH - self._total_ticks) * NIGHT_HOURS_PER_TICK)) @debug_timer("night.render") def render(self, surface, gamestate): -- 2.34.1