Flake8
[tabakrolletjie.git] / tabakrolletjie / scenes / night.py
1 """ In the night, the mould attacks. """
2
3 import pygame.locals as pgl
4
5 import pymunk
6
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
14
15
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)
22         self._turnips = []
23         for turnip_data in gamestate.turnips:
24             turnip = Turnip(space=self._space, **turnip_data)
25             self._turnips.append(turnip)
26
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:
32             turnip.render(surface)
33         self._lights.render_light(surface)
34         self._obstacles.render(surface)
35         self._lights.render_fittings(surface)
36
37     def event(self, ev, gamestate):
38         if ev.type == pgl.KEYDOWN:
39             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
40                 from .menu import MenuScene
41                 SceneChangeEvent.post(scene=MenuScene())
42             if ev.key == pgl.K_e:
43                 from .day import DayScene
44                 SceneChangeEvent.post(scene=DayScene())
45         elif ev.type == pgl.MOUSEBUTTONDOWN:
46             if ev.button == 1:
47                 self._lights.toggle_nearest(ev.pos, surfpos=True)
48                 print self._lights.lit_by(ev.pos, surfpos=True)
49
50     @debug_timer("night.tick")
51     def tick(self, gamestate):
52         self._mould.tick(gamestate, self._space, self._lights)
53         self._lights.tick()
54
55     def exit(self, gamestate):
56         turnip_data = [turnip.serialize() for turnip in self._turnips]
57         gamestate.turnips = turnip_data