Use debug_timer at night.
[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 BaseLight
9 from ..obstacles import BaseObstacle
10 from ..enemies import Boyd
11 from ..events import SceneChangeEvent
12 from ..utils import debug_timer
13
14
15 class NightScene(BaseScene):
16     def enter(self, gamestate):
17         self._space = pymunk.Space()
18         self._obstacles = [
19             BaseObstacle.load(cfg) for cfg in gamestate.station["obstacles"]]
20         self._lights = [
21             BaseLight.load(cfg) for cfg in gamestate.station["lights"]]
22         for obs in self._obstacles:
23             obs.add(self._space)
24         for light in self._lights:
25             light.add(self._space)
26
27         self._mould = Boyd(gamestate, self._space)
28
29     @debug_timer("night.render")
30     def render(self, surface, gamestate):
31         surface.fill((0, 0, 155))
32         for light in self._lights:
33             light.render_light(surface)
34         for obs in self._obstacles:
35             obs.render(surface)
36         for light in self._lights:
37             light.render_fittings(surface)
38         self._mould.render(surface)
39
40     def event(self, ev, gamestate):
41         if ev.type == pgl.KEYDOWN:
42             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
43                 from .menu import MenuScene
44                 SceneChangeEvent.post(scene=MenuScene())
45             elif ev.key == pgl.K_t:
46                 for light in self._lights:
47                     light.toggle()
48
49     @debug_timer("night.tick")
50     def tick(self, gamestate):
51         self._mould.tick(gamestate, self._space)