QuitGameEvent.
authorSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 15:31:56 +0000 (17:31 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 15:31:56 +0000 (17:31 +0200)
naja/engine.py
naja/events.py

index 7529efd357b6c47d0ced7970d45b12476ce59bb8..94ddeab24a055e9134e1c51e7fef68f2a877dd58 100644 (file)
@@ -1,7 +1,7 @@
 import pygame
 import pygame.locals as pgl
 
-from naja.events import SceneChangeEvent
+from naja.events import SceneChangeEvent, QuitGameEvent
 
 
 class Engine(object):
@@ -12,7 +12,8 @@ class Engine(object):
     def run(self):
         while True:
             for ev in pygame.event.get():
-                if ev.type == pgl.QUIT:
+                if ev.type == pgl.QUIT or QuitGameEvent.matches(ev):
+                    self.quit_game()
                     return
                 elif SceneChangeEvent.matches(ev):
                     self.change_scene(ev.scene)
@@ -25,3 +26,7 @@ class Engine(object):
         self._scene.exit()
         self._scene = scene
         self._scene.enter()
+
+    def quit_game(self):
+        self._scene.exit()
+        self._scene = None
index ec1b33f154d3cec2491130cc7b623cab85f5dec7..01df79c162a34b5c652374847296f1623b082fa6 100644 (file)
@@ -27,3 +27,11 @@ class SceneChangeEvent(NajaEvent):
     @classmethod
     def post(cls, scene):
         super(SceneChangeEvent, cls).post(scene=scene)
+
+
+class QuitGameEvent(NajaEvent):
+    TYPE = "QUIT_GAME"
+
+    @classmethod
+    def post(cls):
+        super(QuitGameEvent, cls).post()