From: Simon Cross Date: Sat, 10 Sep 2016 23:22:51 +0000 (+0200) Subject: Merge branch 'master' of ctpug.org.za:tabakrolletjie X-Git-Tag: tabakrolletjie-v1.0.0~18 X-Git-Url: https://git.ctpug.org.za/?p=tabakrolletjie.git;a=commitdiff_plain;h=da0dc03472ab119b77a4706c6a4d3d581e37b50d;hp=03015e9baeb68d6cbfddb9e356d18628ad2966e2 Merge branch 'master' of ctpug.org.za:tabakrolletjie --- diff --git a/tabakrolletjie/scenes/day.py b/tabakrolletjie/scenes/day.py index 8c42b06..2a1cc35 100644 --- a/tabakrolletjie/scenes/day.py +++ b/tabakrolletjie/scenes/day.py @@ -40,8 +40,10 @@ class DayScene(BaseScene): self._tool = None self._light_colors = None self._dragging = None - # Turnip - self.grow_turnips(gamestate) + # 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) @@ -89,17 +91,6 @@ class DayScene(BaseScene): (shadowed_text("Press a key to return to the menu", FONTS["sans"], 24), (350, 400))) - def grow_turnips(self, gamestate): - for turnip_data in gamestate.turnips: - turnip = Turnip(space=self._space, **turnip_data) - # Turnips grow at dawn - seeds = turnip.grow() - if seeds: - gamestate.seeds += seeds - gamestate.harvested += 1 - else: - self._turnips.append(turnip) - def create_tools(self, gamestate): tools = [] @@ -132,14 +123,14 @@ class DayScene(BaseScene): def exit(self, gamestate): self._unset_cursor() - turnip_data = [turnip.serialize() for turnip in self._turnips] - gamestate.turnips = turnip_data def end_day(self, gamestate): if self._ending: return self._battery.apply_recharge() gamestate.update_lights(self._lights) + turnip_data = [turnip.serialize() for turnip in self._turnips] + gamestate.turnips = turnip_data self._ending = True from .night import NightScene SceneChangeEvent.post(scene=NightScene()) diff --git a/tabakrolletjie/scenes/help.py b/tabakrolletjie/scenes/help.py index ca1abd2..648a581 100644 --- a/tabakrolletjie/scenes/help.py +++ b/tabakrolletjie/scenes/help.py @@ -99,7 +99,12 @@ class HelpScene(BaseScene): "This is a pulsating lamp. Its light intensity is variable."), transform=Multiply(colour=COLOURS["cyan"])), HelpItem(("48", "spotlight.png"), ( - "This is a spotlight. Unlike a lamp, it has a rotating beam." + "This is a spotlight. Unlike a lamp, it has a beam which is" + " pointed in a particular direction. To change the direction of" + " a beam, right-click near the spotlight and drag. You can only" + " do this during the day. Some spotlights rotate."), + transform=Multiply(colour=COLOURS["red"])), + HelpItem(("48", "lamp.png"), ( " Lights can be multicoloured, like this one. You can toggle" " lights on and off at night to conserve power, and toggle the" " colour of multicoloured lights."), @@ -178,6 +183,9 @@ class HelpScene(BaseScene): height = 50 x_offset = SCREEN_SIZE[0] / 2 + for tool in self._tools: + tool.render(surface) + def event(self, ev, gamestate): if ev.type == pgl.KEYDOWN: if ev.key in (pgl.K_q, pgl.K_ESCAPE): diff --git a/tabakrolletjie/scenes/load_level.py b/tabakrolletjie/scenes/load_level.py index 7f3223f..015a5f6 100644 --- a/tabakrolletjie/scenes/load_level.py +++ b/tabakrolletjie/scenes/load_level.py @@ -7,7 +7,7 @@ import pygame.locals as pgl from .base import BaseScene from ..constants import SCREEN_SIZE from ..events import SceneChangeEvent -from ..widgets import TextButton +from ..widgets import TextButton, ImageButton from ..loader import loader @@ -35,12 +35,24 @@ class LoadLevelScene(BaseScene): height += button.get_height() + 20 self._buttons.append(button) + self._tools = self.create_tools(gamestate) + + def create_tools(self, gamestate): + tools = [] + tools.append(ImageButton( + '32', 'exit.png', name='exit', + pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40))) + return tools + def render(self, surface, gamestate): surface.fill((0, 128, 128)) self._title.render(surface) for button in self._buttons: button.render(surface) + for tool in self._tools: + tool.render(surface) + def _get_pressed(self, ev): for button in self._buttons: if button.pressed(ev): @@ -62,3 +74,10 @@ class LoadLevelScene(BaseScene): pressed = self._get_pressed(ev) if pressed: self._do_load(pressed.station, gamestate) + else: + # Check tools + for tool in self._tools: + if tool.pressed(ev): + if tool.name == 'exit': + from .menu import MenuScene + SceneChangeEvent.post(scene=MenuScene()) diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 593a03f..9f86745 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -153,6 +153,12 @@ class NightScene(BaseScene): if self._ending: return gamestate.update_lights(self._lights) + # Turnip + self.grow_turnips(gamestate) + turnip_data = [turnip.serialize() for turnip in self._turnips] + gamestate.turnips = turnip_data + gamestate.days += 1 + self._mould.update_resistances(gamestate) self._ending = True from .day import DayScene SceneChangeEvent.post(scene=DayScene()) @@ -202,9 +208,13 @@ class NightScene(BaseScene): if not self.turnip_count and not self._battery.current: self._end_night() - def exit(self, gamestate): - turnip_data = [turnip.serialize() for turnip in self._turnips] - gamestate.turnips = turnip_data - # TODO: Move this into the end_night function - gamestate.days += 1 - self._mould.update_resistances(gamestate) + def grow_turnips(self, gamestate): + """ Turnips grow at the end of the night """ + for turnip in self._turnips[:]: + # Turnips grow at dawn + seeds = turnip.grow() + if seeds: + gamestate.seeds += seeds + gamestate.harvested += 1 + self._turnips.remove(turnip) + # We ignore the body cleanup, since the space is going away