+ self._battery = BatteryManager(gamestate)
+ self._infobar = InfoBar("day", battery=self._battery, scene=self)
+ self._turnips = []
+ self._paused = False
+ self._tool = None
+ self._light_colors = None
+ self._dragging = None
+ # Create Turnips
+ for turnip_data in gamestate.turnips:
+ turnip = Turnip(space=self._space, **turnip_data)
+ self._turnips.append(turnip)
+ # Tools
+ self._light_toolbar = []
+ self._tools = self.create_tools(gamestate)
+ # Background
+ self._soil = loader.load_image(
+ "textures", "soil.png", transform=self.BRIGHTNESS)
+ # Check if we've lost
+ self._game_over_text = []
+ if gamestate.seeds == 0 and len(self._turnips) == 0:
+ self._draw_you_lose(gamestate)
+ elif gamestate.harvested >= gamestate.turnip_target:
+ self._draw_you_win(gamestate)
+ else:
+ write_save_file(gamestate.serialize())
+ self._ending = False
+
+ def _draw_you_lose(self, gamestate):
+ 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), (300, 350)))
+ self._game_over_text.append(
+ (shadowed_text("Press a key to return to the menu",
+ FONTS["sans"], 24), (350, 400)))
+
+ def _draw_you_win(self, gamestate):
+ 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 Win", FONTS["bold"], 48), (400, 280)))
+ self._game_over_text.append(
+ (shadowed_text(
+ ("You have Successfully Harvested %d turnips" %
+ gamestate.harvested),
+ FONTS["sans"], 24),
+ (300, 350)))
+ self._game_over_text.append(
+ (shadowed_text("Press a key to return to the menu",
+ FONTS["sans"], 24), (350, 400)))
+
+ def create_tools(self, gamestate):
+ tools = []
+
+ x, y, step = 50, SCREEN_SIZE[1] - 40, 50
+
+ tools.append(ImageButton('32', 'seed.png', name='seed', pos=(x, y)))
+ x += step
+
+ for light_config in gamestate.station["available_lights"]:
+ tool = ImageButton(
+ '32', '%s.png' % light_config["type"], name='light',
+ pos=(x, y))
+ tool.light_config = light_config
+ tools.append(tool)
+ x += step
+
+ tools.append(ImageButton(
+ '32', 'remove.png', name='remove light', pos=(x, y)))
+ x += step
+
+ tools.append(ImageButton(
+ '32', 'default_cursor.png', name='reset tool', pos=(x, y)))
+
+ tools.append(ImageButton(
+ '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