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
16 from ..constants import NIGHT_LENGTH, DEBUG
19 class NightScene(BaseScene):
21 DARKNESS = Overlay(colour=(0, 0, 0, 150))
23 def enter(self, gamestate):
24 self._space = pymunk.Space()
25 self._obstacles = ObstacleManager(self._space, gamestate)
26 self._lights = LightManager(self._space, gamestate)
27 self._mould = Boyd(gamestate, self._space)
29 for turnip_data in gamestate.turnips:
30 turnip = Turnip(space=self._space, **turnip_data)
31 self._turnips.append(turnip)
32 self._soil = loader.load_image(
33 "textures", "soil.png", transform=self.DARKNESS)
36 @debug_timer("night.render")
37 def render(self, surface, gamestate):
38 surface.blit(self._soil, (0, 0))
40 self._mould.render(surface)
42 for turnip in self._turnips[:]:
44 self._turnips.remove(turnip)
48 turnip.render(surface)
50 self._lights.render_light(surface)
51 self._obstacles.render(surface)
52 self._lights.render_fittings(surface)
54 def event(self, ev, gamestate):
55 if ev.type == pgl.KEYDOWN:
56 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
57 from .menu import MenuScene
58 SceneChangeEvent.post(scene=MenuScene())
59 if ev.key == pgl.K_e and DEBUG:
61 elif ev.type == pgl.MOUSEBUTTONDOWN:
63 self._lights.toggle_nearest(ev.pos, surfpos=True)
64 print self._lights.lit_by(ev.pos, surfpos=True)
68 from .day import DayScene
69 SceneChangeEvent.post(scene=DayScene())
71 @debug_timer("night.tick")
72 def tick(self, gamestate):
73 if self._total_ticks < NIGHT_LENGTH:
74 self._mould.tick(gamestate, self._space, self._lights)
76 print "Power usage: ", self._lights.total_power_usage()
79 if not self._mould.alive():
82 def exit(self, gamestate):
83 turnip_data = [turnip.serialize() for turnip in self._turnips]
84 gamestate.turnips = turnip_data