Rework scenes and allow the user to quit.
[tabakrolletjie.git] / tabakrolletjie / engine.py
index eee88b761dcc168c07c1d8fe85731af1b00a7962..8ee5fc96a43c5a8746c62fa653893a5d9ca34c15 100644 (file)
@@ -11,9 +11,16 @@ from .constants import FPS
 
 
 class Engine(object):
-    def __init__(self, screen, scene):
+    def __init__(self, screen, gamestate):
         self._screen = screen
+        self._gamestate = gamestate
+        self._scene = None
+
+    def set_scene(self, scene):
+        if self._scene is not None:
+            self._scene.exit(self._gamestate)
         self._scene = scene
+        self._scene.enter(self._gamestate)
 
     def run(self):
         clock = pygame.time.Clock()
@@ -24,9 +31,9 @@ class Engine(object):
                 if ev.type == pgl.QUIT:
                     return
                 else:
-                    pass  # TODO: send to scene
+                    self._scene.event(ev, self._gamestate)
 
-            # TODO: render scene
+            self._scene.render(self._screen, self._gamestate)
             pygame.display.flip()
 
             clock.tick(FPS)