1 """ In the night, the mould attacks. """
3 import pygame.locals as pgl
7 from .base import BaseScene
8 from ..lights import LightManager
9 from ..obstacles import ObstacleManager
10 from ..enemies import Boyd
11 from ..events import SceneChangeEvent
12 from ..utils import debug_timer
13 from ..loader import loader
14 from ..transforms import Overlay
15 from ..turnip import Turnip
18 class NightScene(BaseScene):
20 DARKNESS = Overlay(colour=(0, 0, 0, 150))
22 def enter(self, gamestate):
23 self._space = pymunk.Space()
24 self._obstacles = ObstacleManager(self._space, gamestate)
25 self._lights = LightManager(self._space, gamestate)
26 self._mould = Boyd(gamestate, self._space)
28 for turnip_data in gamestate.turnips:
29 turnip = Turnip(space=self._space, **turnip_data)
30 self._turnips.append(turnip)
31 self._soil = loader.load_image(
32 "textures", "soil.png", transform=self.DARKNESS)
34 @debug_timer("night.render")
35 def render(self, surface, gamestate):
36 surface.blit(self._soil, (0, 0))
38 self._mould.render(surface)
40 for turnip in self._turnips[:]:
42 self._turnips.remove(turnip)
46 turnip.render(surface)
48 self._lights.render_light(surface)
49 self._obstacles.render(surface)
50 self._lights.render_fittings(surface)
52 def event(self, ev, gamestate):
53 if ev.type == pgl.KEYDOWN:
54 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
55 from .menu import MenuScene
56 SceneChangeEvent.post(scene=MenuScene())
58 from .day import DayScene
59 SceneChangeEvent.post(scene=DayScene())
60 elif ev.type == pgl.MOUSEBUTTONDOWN:
62 self._lights.toggle_nearest(ev.pos, surfpos=True)
63 print self._lights.lit_by(ev.pos, surfpos=True)
65 @debug_timer("night.tick")
66 def tick(self, gamestate):
67 self._mould.tick(gamestate, self._space, self._lights)
70 def exit(self, gamestate):
71 turnip_data = [turnip.serialize() for turnip in self._turnips]
72 gamestate.turnips = turnip_data