Merge branch 'master' of ctpug.org.za:tabakrolletjie
[tabakrolletjie.git] / tabakrolletjie / scenes / day.py
index 4ab14e713fc8b51f6f2ed2cbb4fb8ee09dece8e6..4cc42f893d8dc1203a330fb401a25fd01ad18e1a 100644 (file)
@@ -3,6 +3,7 @@
 import math
 
 import pygame.display
+import pygame.surface
 import pygame.locals as pgl
 
 import pymunk
@@ -12,7 +13,7 @@ from .base import BaseScene
 from ..lights import LightManager, light_fitting_by_type
 from ..obstacles import ObstacleManager
 from ..events import SceneChangeEvent
-from ..utils import debug_timer
+from ..utils import debug_timer, shadowed_text
 from ..loader import loader
 from ..transforms import Overlay, Alpha, ColourWedges
 
@@ -46,6 +47,24 @@ class DayScene(BaseScene):
         # Background
         self._soil = loader.load_image(
             "textures", "soil.png", transform=self.BRIGHTNESS)
+        # Check if we've lost
+        self._game_over_text = []
+        if self._seeds == 0 and len(self._turnips) == 0:
+            self._draw_game_over_text()
+
+    def _draw_game_over_text(self):
+        overlay = pygame.surface.Surface(
+            (SCREEN_SIZE[0], 240), pgl.SWSURFACE).convert_alpha()
+        overlay.fill((0, 0, 0, 128))
+        self._game_over_text.append((overlay, (0, 250)))
+        self._game_over_text.append(
+            (shadowed_text("You Lost", FONTS["bold"], 48), (400, 280)))
+        self._game_over_text.append(
+            (shadowed_text("You have no seeds and no turnips growing",
+                           FONTS["sans"], 24), (250, 350)))
+        self._game_over_text.append(
+            (shadowed_text("Press a key to return to the menu",
+                           FONTS["sans"], 24), (250, 400)))
 
     def grow_turnips(self, gamestate):
         for turnip_data in gamestate.turnips:
@@ -60,7 +79,11 @@ class DayScene(BaseScene):
 
     def create_tools(self, gamestate):
         tools = []
-        x, y, step = 50, SCREEN_SIZE[1] - 40, 50
+        x, y, step = 0, SCREEN_SIZE[1] - 40, 50
+
+        tools.append(ImageButton(
+            '32', 'default_cursor.png', name='reset tool', pos=(x, y)))
+        x += step
         tools.append(ImageButton('32', 'seed.png', name='seed', pos=(x, y)))
         x += step
 
@@ -73,7 +96,9 @@ class DayScene(BaseScene):
             x += step
 
         tools.append(ImageButton(
-            '32', 'default_cursor.png', name='reset tool', pos=(x, y)))
+            '32', 'night.png', name='start night', pos=(SCREEN_SIZE[0] - 100, y)))
+        tools.append(ImageButton(
+            '32', 'exit.png', name='exit', pos=(SCREEN_SIZE[0] - 50, y)))
         return tools
 
     def exit(self, gamestate):
@@ -98,6 +123,9 @@ class DayScene(BaseScene):
         for light_tool in self._light_toolbar:
             light_tool.render(surface)
         self._draw_cursor(surface)
+        if self._game_over_text:
+            for surf, pos in self._game_over_text:
+                surface.blit(surf, pos)
 
     def _draw_light_toolbar(self, light_config, x):
         height = SCREEN_SIZE[1] - 80
@@ -165,6 +193,10 @@ class DayScene(BaseScene):
             self._lights.add_light(cfg)
 
     def event(self, ev, gamestate):
+        if self._game_over_text:
+            if ev.type in (pgl.KEYDOWN, pgl.MOUSEBUTTONDOWN):
+                from .menu import MenuScene
+                SceneChangeEvent.post(scene=MenuScene())
         if ev.type == pgl.KEYDOWN:
             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
                 from .menu import MenuScene
@@ -184,6 +216,12 @@ class DayScene(BaseScene):
                             self._unset_cursor()
                             self._tool = None
                             self._clear_light_toolbar()
+                        elif tool.name == 'start night':
+                            from .night import NightScene
+                            SceneChangeEvent.post(scene=NightScene())
+                        elif tool.name == 'exit':
+                            from .menu import MenuScene
+                            SceneChangeEvent.post(scene=MenuScene())
                         else:
                             self._tool = tool
                             if self._tool.name == 'seed':