Merge branch 'master' of ctpug.org.za:tabakrolletjie
[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 ..events import SceneChangeEvent
11
12
13 class NightScene(BaseScene):
14     def enter(self, gamestate):
15         self._space = pymunk.Space()
16         self._obstacles = [
17             BaseObstacle.load(cfg) for cfg in gamestate.station["obstacles"]]
18         self._lights = [
19             BaseLight.load(cfg) for cfg in gamestate.station["lights"]]
20         for obs in self._obstacles:
21             obs.add(self._space)
22         for light in self._lights:
23             light.add(self._space)
24
25     def render(self, surface, gamestate):
26         surface.fill((0, 0, 155))
27         for obs in self._obstacles:
28             obs.render(surface)
29         for light in self._lights:
30             light.render(surface)
31
32     def event(self, ev, gamestate):
33         if ev.type == pgl.KEYDOWN:
34             if ev.key in (pgl.K_q, pgl.K_ESCAPE):
35                 from .menu import MenuScene
36                 SceneChangeEvent.post(scene=MenuScene())