Display power usage per hour.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 19:18:08 +0000 (21:18 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 19:18:08 +0000 (21:18 +0200)
tabakrolletjie/constants.py
tabakrolletjie/infobar.py
tabakrolletjie/scenes/day.py
tabakrolletjie/scenes/night.py

index 0ea58f52a260aba732d68e84a8f8be7b2652bf0a..63e13dd63ebf6f53ec36567469642373203d263b 100644 (file)
@@ -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
index ac9f1a95923f53b4aa1b5eb702428e617d6bfe94..6697892708fbfefba1eaf741e9050a7909b1ddaf 100644 (file)
@@ -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
index 1e65fe10794b0e3e05c2a97339df7672ecbcd702..cc7a32e1cf1b1b41cd2bb6508f90f9159fd597f5 100644 (file)
@@ -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):
index e4cc73384b9c433f61755cfd16fe73a35226770f..580d140a6941475cfeefc1f295e2b51ec82312b7 100644 (file)
@@ -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):