From 77c817eaeef44416ff09cd53024db9a80f032ba4 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sun, 11 May 2014 19:03:56 +0200 Subject: [PATCH] Make scenes take the game state. --- naja/engine.py | 6 +++--- naja/events.py | 4 ++-- naja/scenes/scene.py | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) 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): -- 2.34.1