1 """ In the night, the mould attacks. """
3 import pygame.locals as pgl
8 from .base import BaseScene
9 from ..lights import LightManager
10 from ..obstacles import ObstacleManager
11 from ..enemies import Boyd
12 from ..events import SceneChangeEvent
13 from ..utils import debug_timer
14 from ..loader import loader
15 from ..turnip import Turnip
18 class NightScene(BaseScene):
19 def enter(self, gamestate):
20 self._space = pymunk.Space()
21 self._obstacles = ObstacleManager(self._space, gamestate)
22 self._lights = LightManager(self._space, gamestate)
23 self._mould = Boyd(gamestate, self._space)
25 for turnip_data in gamestate.turnips:
26 turnip = Turnip(space=self._space, **turnip_data)
27 self._turnips.append(turnip)
29 @debug_timer("night.render")
30 def render(self, surface, gamestate):
31 surface.blit(loader.load_image("textures", "soil.png"), (0, 0))
32 darkness = pygame.surface.Surface(surface.get_size())
33 darkness = darkness.convert_alpha()
34 darkness.fill((0, 0, 0, 150))
35 surface.blit(darkness, (0, 0))
37 self._mould.render(surface)
39 for turnip in self._turnips[:]:
41 self._turnips.remove(turnip)
45 turnip.render(surface)
46 self._lights.render_light(surface)
47 self._obstacles.render(surface)
48 self._lights.render_fittings(surface)
50 def event(self, ev, gamestate):
51 if ev.type == pgl.KEYDOWN:
52 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
53 from .menu import MenuScene
54 SceneChangeEvent.post(scene=MenuScene())
56 from .day import DayScene
57 SceneChangeEvent.post(scene=DayScene())
58 elif ev.type == pgl.MOUSEBUTTONDOWN:
60 self._lights.toggle_nearest(ev.pos, surfpos=True)
61 print self._lights.lit_by(ev.pos, surfpos=True)
63 @debug_timer("night.tick")
64 def tick(self, gamestate):
65 self._mould.tick(gamestate, self._space, self._lights)
68 def exit(self, gamestate):
69 turnip_data = [turnip.serialize() for turnip in self._turnips]
70 gamestate.turnips = turnip_data