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(space=self._space, **turnip_data)
25 self._turnips.append(turnip)
27 @debug_timer("night.render")
28 def render(self, surface, gamestate):
29 surface.fill((0, 0, 155))
30 self._mould.render(surface)
31 for turnip in self._turnips[:]:
33 self._turnips.remove(turnip)
37 turnip.render(surface)
38 self._lights.render_light(surface)
39 self._obstacles.render(surface)
40 self._lights.render_fittings(surface)
42 def event(self, ev, gamestate):
43 if ev.type == pgl.KEYDOWN:
44 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
45 from .menu import MenuScene
46 SceneChangeEvent.post(scene=MenuScene())
48 from .day import DayScene
49 SceneChangeEvent.post(scene=DayScene())
50 elif ev.type == pgl.MOUSEBUTTONDOWN:
52 self._lights.toggle_nearest(ev.pos, surfpos=True)
53 print self._lights.lit_by(ev.pos, surfpos=True)
55 @debug_timer("night.tick")
56 def tick(self, gamestate):
57 self._mould.tick(gamestate, self._space, self._lights)
60 def exit(self, gamestate):
61 turnip_data = [turnip.serialize() for turnip in self._turnips]
62 gamestate.turnips = turnip_data