import math
import pygame.display
+import pygame.surface
import pygame.locals as pgl
import pymunk
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
# 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:
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
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 = []
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