Add end day.
authorSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 14:47:56 +0000 (16:47 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 10 Sep 2016 14:47:56 +0000 (16:47 +0200)
tabakrolletjie/scenes/day.py

index 968f241c97d32247611749e88713612fcc6af8af..aff92a61507cf45dec0191c6ca14bc635fc50b0a 100644 (file)
@@ -10,6 +10,7 @@ import pymunk
 import pymunk.pygame_util
 
 from .base import BaseScene
+from ..battery import BatteryManager
 from ..lights import LightManager, light_fitting_by_type
 from ..obstacles import ObstacleManager
 from ..events import SceneChangeEvent
@@ -31,6 +32,7 @@ class DayScene(BaseScene):
         self._toolbar_font = loader.load_font(FONTS['sans'], size=20)
         self._obstacles = ObstacleManager(self._space, gamestate)
         self._lights = LightManager(self._space, gamestate)
+        self._battery = BatteryManager(gamestate)
         self._turnips = []
         self._seeds = gamestate.seeds
         self._harvested = gamestate.harvested
@@ -109,6 +111,11 @@ class DayScene(BaseScene):
         turnip_data = [turnip.serialize() for turnip in self._turnips]
         gamestate.turnips = turnip_data
 
+    def end_day(self, gamestate):
+        self._battery.apply_recharge()
+        from .night import NightScene
+        SceneChangeEvent.post(scene=NightScene())
+
     @debug_timer("day.render")
     def render(self, surface, gamestate):
         surface.blit(self._soil, (0, 0))
@@ -203,8 +210,7 @@ class DayScene(BaseScene):
                 from .menu import MenuScene
                 SceneChangeEvent.post(scene=MenuScene())
             elif ev.key == pgl.K_e:
-                from .night import NightScene
-                SceneChangeEvent.post(scene=NightScene())
+                self.end_day(gamestate)
             elif ev.key == pgl.K_SPACE:
                 self._paused = not self._paused
         elif ev.type == pgl.MOUSEBUTTONDOWN:
@@ -218,8 +224,7 @@ class DayScene(BaseScene):
                             self._tool = None
                             self._clear_light_toolbar()
                         elif tool.name == 'start night':
-                            from .night import NightScene
-                            SceneChangeEvent.post(scene=NightScene())
+                            self.end_day(gamestate)
                         elif tool.name == 'exit':
                             from .menu import MenuScene
                             SceneChangeEvent.post(scene=MenuScene())