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 ..turnip import Turnip
16 class NightScene(BaseScene):
17 def enter(self, gamestate):
18 self._space = pymunk.Space()
19 self._obstacles = ObstacleManager(self._space, gamestate)
20 self._lights = LightManager(self._space, gamestate)
21 self._mould = Boyd(gamestate, self._space)
23 for turnip_data in gamestate.turnips:
24 turnip = Turnip(**turnip_data)
25 self._turnips.append(turnip)
28 @debug_timer("night.render")
29 def render(self, surface, gamestate):
30 surface.fill((0, 0, 155))
31 self._mould.render(surface)
32 for turnip in self._turnips:
33 turnip.render(surface)
34 self._lights.render_light(surface)
35 self._obstacles.render(surface)
36 self._lights.render_fittings(surface)
38 def event(self, ev, gamestate):
39 if ev.type == pgl.KEYDOWN:
40 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
41 from .menu import MenuScene
42 SceneChangeEvent.post(scene=MenuScene())
44 from .day import DayScene
45 SceneChangeEvent.post(scene=DayScene())
46 elif ev.type == pgl.MOUSEBUTTONDOWN:
48 self._lights.toggle_nearest(ev.pos, surfpos=True)
49 print self._lights.lit_by(ev.pos, surfpos=True)
51 @debug_timer("night.tick")
52 def tick(self, gamestate):
53 self._mould.tick(gamestate, self._space, self._lights)
56 def exit(self, gamestate):
57 turnip_data = [turnip.serialize() for turnip in self._turnips]
58 gamestate.turnips = turnip_data