From ee6c1bb0edd607fb04b5e64cd27b2535b1143e4e Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 10 Sep 2016 16:04:22 +0200 Subject: [PATCH] Add 'game over' check and display --- tabakrolletjie/scenes/day.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 4c81130..334e59f 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -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 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, Multiply, Alpha @@ -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: @@ -61,7 +80,7 @@ class DayScene(BaseScene): def create_tools(self, gamestate): tools = [] x, y, step = 0, SCREEN_SIZE[1] - 40, 50 - + tools.append(ImageButton( '32', 'default_cursor.png', name='reset tool', pos=(x, y))) x += step @@ -104,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): self._light_toolbar = [] @@ -166,6 +188,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 -- 2.34.1