From: Simon Cross Date: Sun, 11 May 2014 15:31:56 +0000 (+0200) Subject: QuitGameEvent. X-Git-Tag: 0.1~424 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=1c288309623b4f09c2a629c877fa9f3de106dd5b;p=naja.git QuitGameEvent. --- diff --git a/naja/engine.py b/naja/engine.py index 7529efd..94ddeab 100644 --- a/naja/engine.py +++ b/naja/engine.py @@ -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 diff --git a/naja/events.py b/naja/events.py index ec1b33f..01df79c 100644 --- a/naja/events.py +++ b/naja/events.py @@ -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()