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 """ A list of actors. """
87 self._actors.append(actor)
90 def remove(self, actor):
91 self._actors.remove(actor)
94 def draw(self, screen):
95 for actor in self._actors:
96 actor.draw() # TODO: allow an option screen to be passed in
100 """ Base class for scenes. """
103 self.actors = Actors()
111 def update(self, dt):
114 def draw(self, screen):
116 self.actors.draw(screen)
118 def on_mouse_down(self, pos, button):
121 def on_mouse_up(self, pos, button):
124 def on_key_down(self, key, mod, unicode):
127 def on_key_up(self, key, mod):
130 def on_music_end(self):