Actually end the night on timeout. Also end the night if Boyd dies out
[tabakrolletjie.git] / tabakrolletjie / scenes / night.py
index f9935d32d761b7f1e9df8d9165b2db121b86cd77..6d4e2bca431f1211d30f445c71dc76962f1f57c9 100644 (file)
@@ -57,20 +57,27 @@ class NightScene(BaseScene):
                 from .menu import MenuScene
                 SceneChangeEvent.post(scene=MenuScene())
             if ev.key == pgl.K_e:
-                from .day import DayScene
-                SceneChangeEvent.post(scene=DayScene())
+                self._to_day()
         elif ev.type == pgl.MOUSEBUTTONDOWN:
             if ev.button == 1:
                 self._lights.toggle_nearest(ev.pos, surfpos=True)
                 print self._lights.lit_by(ev.pos, surfpos=True)
 
+    def _to_day(self):
+        # End the night
+        from .day import DayScene
+        SceneChangeEvent.post(scene=DayScene())
+
     @debug_timer("night.tick")
     def tick(self, gamestate):
         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()
-        self._total_ticks += 1
+        else:
+            self._to_day()
+        if not self._mould.alive():
+            self._to_day()
 
     def exit(self, gamestate):
         turnip_data = [turnip.serialize() for turnip in self._turnips]