3 import pygame.locals as pgl
6 import pymunk.pygame_util
8 from .base import BaseScene
9 from ..lights import LightManager
10 from ..obstacles import ObstacleManager
11 from ..events import SceneChangeEvent
12 from ..utils import debug_timer
14 from ..constants import SCREEN_SIZE
15 from ..widgets import ImageButton
18 class DayScene(BaseScene):
19 def enter(self, gamestate):
20 self._space = pymunk.Space()
21 self._obstacles = ObstacleManager(self._space, gamestate)
22 self._lights = LightManager(self._space, gamestate)
25 ImageButton('32', 'seed.png', name='seed',
26 pos=(50, SCREEN_SIZE[1] - 40)),
27 ImageButton('32', 'default_cursor.png', name='reset tool',
28 pos=(SCREEN_SIZE[0] - 50, SCREEN_SIZE[1] - 40)),
31 def exit(self, gamestate):
34 @debug_timer("day.render")
35 def render(self, surface, gamestate):
36 surface.fill((0, 0, 155))
37 self._lights.render_light(surface)
38 self._obstacles.render(surface)
39 self._lights.render_fittings(surface)
40 for tool in self._tools:
42 self._draw_cursor(surface)
44 def event(self, ev, gamestate):
45 if ev.type == pgl.KEYDOWN:
46 if ev.key in (pgl.K_q, pgl.K_ESCAPE):
47 from .menu import MenuScene
48 SceneChangeEvent.post(scene=MenuScene())
50 from .night import NightScene
51 SceneChangeEvent.post(scene=NightScene())
52 elif ev.type == pgl.MOUSEBUTTONDOWN:
55 for tool in self._tools:
57 print 'tool', tool.name
58 if tool.name == 'reset tool':
61 self._set_cursor(tool.name)
63 # Not tool, so check lights
64 self._lights.toggle_nearest(ev.pos, surfpos=True)
65 print self._lights.lit_by(ev.pos, surfpos=True)
67 @debug_timer("day.tick")
68 def tick(self, gamestate):