From: Simon Cross Date: Sun, 11 May 2014 17:03:56 +0000 (+0200) Subject: Make scenes take the game state. X-Git-Tag: 0.1~403 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=77c817eaeef44416ff09cd53024db9a80f032ba4;p=naja.git Make scenes take the game state. --- diff --git a/naja/engine.py b/naja/engine.py index 32c139f..cbe27ce 100644 --- a/naja/engine.py +++ b/naja/engine.py @@ -20,16 +20,16 @@ class Engine(object): self.quit_game() return elif SceneChangeEvent.matches(ev): - self.change_scene(ev.scene) + self.change_scene(ev.scene_cls) else: self._scene.handle_event(ev) self._scene.render(self._surface) pygame.display.flip() clock.tick(FPS) - def change_scene(self, scene): + def change_scene(self, scene_cls): self._scene.exit() - self._scene = scene + self._scene = scene_cls(self._state) self._scene.enter() def quit_game(self): diff --git a/naja/events.py b/naja/events.py index 01df79c..4d3fb07 100644 --- a/naja/events.py +++ b/naja/events.py @@ -25,8 +25,8 @@ class SceneChangeEvent(NajaEvent): TYPE = "SCENE_CHANGE" @classmethod - def post(cls, scene): - super(SceneChangeEvent, cls).post(scene=scene) + def post(cls, scene_cls): + super(SceneChangeEvent, cls).post(scene_cls=scene_cls) class QuitGameEvent(NajaEvent): diff --git a/naja/scenes/scene.py b/naja/scenes/scene.py index f0acf21..ce0b684 100644 --- a/naja/scenes/scene.py +++ b/naja/scenes/scene.py @@ -9,7 +9,8 @@ class Scene(object): E.g. Splash screen, game board, credits, win, lose. """ - def __init__(self): + def __init__(self, state): + self.state = state self.widgets = [] def enter(self):