Actually end the night on timeout. Also end the night if Boyd dies out
authorNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 12:00:04 +0000 (14:00 +0200)
committerNeil <neil@dip.sun.ac.za>
Sat, 10 Sep 2016 12:00:27 +0000 (14:00 +0200)
tabakrolletjie/enemies.py
tabakrolletjie/scenes/night.py

index 59151d561d40bad83cc7a1711acb5c3339addc2c..80a0776ee4736ac63ab55c13144c7c00df226c54 100644 (file)
@@ -26,7 +26,7 @@ MAX_AGE = 60
 MAX_ELEMENTS = 400
 MAX_HEALTH = 100
 
-MOULD_STAGES = [10, 20]
+MOULD_STAGES = [15, 25]
 
 
 class Mould(pymunk.Body):
@@ -186,3 +186,6 @@ class Boyd(object):
     def render(self, surface):
         """Draw ourselves"""
         surface.blit(self._image, (0, 0), None, 0)
+
+    def alive(self):
+        return len(self._moulds) > 0
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]