1 """ Scene utilities. """
7 """ Decorator that applies events to an engine. """
9 def wrap(self, *args, **kw):
10 events = f(self, *args, **kw)
11 self._apply_events(events)
16 """ A holder for game state. """
18 def __init__(self, app, scene):
22 def _apply_events(self, events):
28 def change_scene(self, scene):
35 return self._scene.update(dt)
38 self._scene.draw(self._app.screen)
41 def on_mouse_down(self, pos, button):
42 return self._scene.on_mouse_down(pos, button)
45 def on_mouse_up(self, pos, button):
46 return self._scene.on_mouse_up(pos, button)
49 def on_key_down(self, key, mod, unicode):
50 return self._scene.on_key_down(key, mod, unicode)
53 def on_key_up(self, key, mod):
54 return self._scene.on_key_up(key, mod)
57 def on_music_end(self):
58 return self._scene.on_music_end()
62 """ Base class for events. """
64 ENGINE_METHOD = "unknown_event"
66 def __init__(self, *args, **kw):
70 def apply(self, engine):
71 getattr(engine, self.ENGINE_METHOD)(*self._args, **self._kw)
74 class ChangeSceneEvent(Event):
75 """ Change to a new scene. """
77 ENGINE_METHOD = "change_scene"
81 """ Base class for scenes. """
92 def draw(self, screen):
95 def on_mouse_down(self, pos, button):
98 def on_mouse_up(self, pos, button):
101 def on_key_down(self, key, mod, unicode):
104 def on_key_up(self, key, mod):
107 def on_music_end(self):