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 LightManager
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"]]
24 for obs in self._obstacles:
26 self._lights = LightManager(self._space, gamestate)
28 @debug_timer("day.render")
29 def render(self, surface, gamestate):
30 surface.fill((0, 0, 155))
31 self._lights.render_light(surface)
32 for obs in self._obstacles:
34 self._lights.render_fittings(surface)
36 def left_click(self, surfpos):
37 pos = pymunk.pygame_util.from_pygame(
38 surfpos, pygame.display.get_surface())
39 point_info = self._space.point_query_nearest(pos, 1.0, CLICK_FILTER)
40 if point_info is not None:
41 point_info.shape.body.light.toggle()
43 def right_click(self, pos):
46 def event(self, ev, gamestate):
47 if ev.type == pgl.KEYDOWN:
48 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
49 from .menu import MenuScene
50 SceneChangeEvent.post(scene=MenuScene())
51 elif ev.key == pgl.K_t:
52 for light in self._lights:
54 elif ev.type == pgl.MOUSEBUTTONDOWN:
56 self.left_click(ev.pos)
58 self.right_click(ev.pos)
60 @debug_timer("day.tick")
61 def tick(self, gamestate):