Make scenes take the game state.
authorSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 17:03:56 +0000 (19:03 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 17:06:46 +0000 (19:06 +0200)
naja/engine.py
naja/events.py
naja/scenes/scene.py

index 32c139f8a56f17427b0a426bdb3b1e2fe3ec338d..cbe27ce0b9ffe7d56da3bc9814b111815a46d84b 100644 (file)
@@ -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):
index 01df79c162a34b5c652374847296f1623b082fa6..4d3fb07f80a94bc5502edfa048b3e0e017c80393 100644 (file)
@@ -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):
index f0acf21bdf9f62a1f9fef85a1f3ce4771234c116..ce0b68488eb1a0dc6369fa37c3dd4902cdb8d3e8 100644 (file)
@@ -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):