4 import pygame.locals as pgl
7 import pymunk.pygame_util
9 from .base import BaseScene
10 from ..constants import FITTINGS_CATEGORY
11 from ..lights import BaseLight
12 from ..obstacles import BaseObstacle
13 from ..events import SceneChangeEvent
14 from ..utils import debug_timer
16 CLICK_FILTER = pymunk.ShapeFilter(mask=FITTINGS_CATEGORY)
19 class DayScene(BaseScene):
20 def enter(self, gamestate):
21 self._space = pymunk.Space()
23 BaseObstacle.load(cfg) for cfg in gamestate.station["obstacles"]]
25 BaseLight.load(cfg) for cfg in gamestate.station["lights"]]
26 for obs in self._obstacles:
28 for light in self._lights:
29 light.add(self._space)
31 @debug_timer("day.render")
32 def render(self, surface, gamestate):
33 surface.fill((0, 0, 155))
34 for light in self._lights:
35 light.render_light(surface)
36 for obs in self._obstacles:
38 for light in self._lights:
39 light.render_fittings(surface)
41 def left_click(self, surfpos):
42 pos = pymunk.pygame_util.from_pygame(
43 surfpos, pygame.display.get_surface())
44 point_info = self._space.point_query_nearest(pos, 1.0, CLICK_FILTER)
45 if point_info is not None:
46 point_info.shape.body.light.toggle()
48 def right_click(self, pos):
51 def event(self, ev, gamestate):
52 if ev.type == pgl.KEYDOWN:
53 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
54 from .menu import MenuScene
55 SceneChangeEvent.post(scene=MenuScene())
56 elif ev.key == pgl.K_t:
57 for light in self._lights:
59 elif ev.type == pgl.MOUSEBUTTONDOWN:
61 self.left_click(ev.pos)
63 self.right_click(ev.pos)
65 @debug_timer("day.tick")
66 def tick(self, gamestate):