import pygame
import pygame.locals as pgl
-from naja.events import SceneChangeEvent
+from naja.events import SceneChangeEvent, QuitGameEvent
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)
self._scene.exit()
self._scene = scene
self._scene.enter()
+
+ def quit_game(self):
+ self._scene.exit()
+ self._scene = None
@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()