From: Simon Cross Date: Sat, 10 Sep 2016 19:18:08 +0000 (+0200) Subject: Display power usage per hour. X-Git-Tag: tabakrolletjie-v1.0.0~52 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;ds=inline;h=923e068edb27b9b6d35359e496668038a1db6fa4;p=tabakrolletjie.git Display power usage per hour. --- 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):