From 1c288309623b4f09c2a629c877fa9f3de106dd5b Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sun, 11 May 2014 17:31:56 +0200 Subject: [PATCH] QuitGameEvent. --- naja/engine.py | 9 +++++++-- naja/events.py | 8 ++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) 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() -- 2.34.1