Hide 'end the night' keypress option behind DEBUG
[tabakrolletjie.git] / tabakrolletjie / scenes / night.py
index ff982139ac114df3147f134e8e6988e2a7b5fc69..6b42f6bf878dafad72ef01fc63077230c71cc8b4 100644 (file)
@@ -13,6 +13,7 @@ from ..utils import debug_timer
 from ..loader import loader
 from ..transforms import Overlay
 from ..turnip import Turnip
+from ..constants import NIGHT_LENGTH, DEBUG
 
 
 class NightScene(BaseScene):
@@ -30,6 +31,7 @@ class NightScene(BaseScene):
             self._turnips.append(turnip)
         self._soil = loader.load_image(
             "textures", "soil.png", transform=self.DARKNESS)
+        self._total_ticks = 0
 
     @debug_timer("night.render")
     def render(self, surface, gamestate):
@@ -54,19 +56,28 @@ class NightScene(BaseScene):
             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
                 from .menu import MenuScene
                 SceneChangeEvent.post(scene=MenuScene())
-            if ev.key == pgl.K_e:
-                from .day import DayScene
-                SceneChangeEvent.post(scene=DayScene())
+            if ev.key == pgl.K_e and DEBUG:
+                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):
-        self._mould.tick(gamestate, self._space, self._lights)
-        self._lights.tick()
-        print "Power usage: ", self._lights.total_power_usage()
+        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()
+        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]