Lights off when battery dies.
[tabakrolletjie.git] / tabakrolletjie / scenes / night.py
index 99b903b84300d2e205e82f8568829e07b4e4a177..115630ab65ef5e143e0266665b12d7e0af8570b9 100644 (file)
@@ -29,6 +29,7 @@ class NightScene(BaseScene):
         self._obstacles = ObstacleManager(self._space, gamestate)
         self._lights = LightManager(self._space, gamestate)
         self._battery = BatteryManager(gamestate)
+        self.check_battery()
         self._infobar = InfoBar("day", battery=self._battery, scene=self)
         self._mould = Boyd(gamestate, self._space)
         self._turnips = []
@@ -106,7 +107,6 @@ class NightScene(BaseScene):
                 self._to_day()
             if ev.button == 1:
                 self._lights.toggle_nearest(ev.pos, surfpos=True)
-                print self._lights.lit_by(ev.pos, surfpos=True)
 
                 # Check tools
                 for tool in self._tools:
@@ -148,13 +148,20 @@ class NightScene(BaseScene):
             (shadowed_text("Press any key to continue", FONTS["sans"], 24),
              (350, 240)))
 
+    def check_battery(self):
+        if self._battery.current == 0:
+            self._lights.battery_dead()
+
     @debug_timer("night.tick")
     def tick(self, gamestate):
         if self._do_ticks and not self._paused:
             if self._total_ticks < NIGHT_LENGTH:
                 self._mould.tick(gamestate, self._space, self._lights)
                 self._lights.tick()
-                print "Power usage: ", self._lights.total_power_usage()
+                if self._total_ticks % 60 == 0:
+                    self._battery.current -= int(
+                        self._lights.total_power_usage())
+                    self.check_battery()
                 self._total_ticks += 1
             else:
                 self._end_night()