X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Fscenes%2Fnight.py;h=fe1fae3860d1d87bcb2b8a77d2ff895afff904ed;hb=3f3f85d9bb45ae64540f3a725915466a2f187a9e;hp=3504461ea71fd1cdeb42f99f66242da09f27034a;hpb=41afa186b508d7b5596a749acfa7ff112afb4a35;p=tabakrolletjie.git diff --git a/tabakrolletjie/scenes/night.py b/tabakrolletjie/scenes/night.py index 3504461..fe1fae3 100644 --- a/tabakrolletjie/scenes/night.py +++ b/tabakrolletjie/scenes/night.py @@ -1,6 +1,7 @@ """ In the night, the mould attacks. """ import pygame.locals as pgl +import pygame.surface import pymunk @@ -10,6 +11,8 @@ from ..obstacles import ObstacleManager from ..enemies import Boyd from ..events import SceneChangeEvent from ..utils import debug_timer +from ..loader import loader +from ..turnip import Turnip class NightScene(BaseScene): @@ -18,11 +21,28 @@ class NightScene(BaseScene): self._obstacles = ObstacleManager(self._space, gamestate) self._lights = LightManager(self._space, gamestate) self._mould = Boyd(gamestate, self._space) + self._turnips = [] + for turnip_data in gamestate.turnips: + turnip = Turnip(space=self._space, **turnip_data) + self._turnips.append(turnip) @debug_timer("night.render") def render(self, surface, gamestate): - surface.fill((0, 0, 155)) + surface.blit(loader.load_image("textures", "soil.png"), (0, 0)) + darkness = pygame.surface.Surface(surface.get_size()) + darkness = darkness.convert_alpha() + darkness.fill((0, 0, 0, 150)) + surface.blit(darkness, (0, 0)) + self._mould.render(surface) + + for turnip in self._turnips[:]: + if turnip.eaten: + self._turnips.remove(turnip) + turnip.remove() + gamestate.eaten += 1 + else: + turnip.render(surface) self._lights.render_light(surface) self._obstacles.render(surface) self._lights.render_fittings(surface) @@ -32,6 +52,9 @@ class NightScene(BaseScene): if ev.key in (pgl.K_q, pgl.K_ESCAPE): from .menu import MenuScene SceneChangeEvent.post(scene=MenuScene()) + if ev.key == pgl.K_e: + from .day import DayScene + SceneChangeEvent.post(scene=DayScene()) elif ev.type == pgl.MOUSEBUTTONDOWN: if ev.button == 1: self._lights.toggle_nearest(ev.pos, surfpos=True) @@ -39,4 +62,9 @@ class NightScene(BaseScene): @debug_timer("night.tick") def tick(self, gamestate): - self._mould.tick(gamestate, self._space) + self._mould.tick(gamestate, self._space, self._lights) + self._lights.tick() + + def exit(self, gamestate): + turnip_data = [turnip.serialize() for turnip in self._turnips] + gamestate.turnips = turnip_data