From: Neil Date: Sat, 10 Sep 2016 14:04:22 +0000 (+0200) Subject: Add 'game over' check and display X-Git-Tag: tabakrolletjie-v1.0.0~97^2~2 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=ee6c1bb0edd607fb04b5e64cd27b2535b1143e4e;p=tabakrolletjie.git Add 'game over' check and display --- 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