From 9959d703e59a5baa3aaad6fd3d5de88385f7c3e0 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sun, 11 May 2014 17:12:42 +0200 Subject: [PATCH] Scene changing. --- naja/engine.py | 12 +++++++++++- naja/events.py | 7 ++++--- naja/scenes/scene.py | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/naja/engine.py b/naja/engine.py index fc58f18..2278fa0 100644 --- a/naja/engine.py +++ b/naja/engine.py @@ -1,6 +1,8 @@ import pygame import pygame.locals as pgl +from naja.events import SceneChangeEvent + class Engine(object): def __init__(self, surface, scene): @@ -12,6 +14,14 @@ class Engine(object): for ev in pygame.event.get(): if ev.type == pgl.QUIT: return - self._scene.handle_event() + elif SceneChangeEvent.matches(ev): + self.change_scene(ev.scene) + else: + self._scene.handle_event() # TODO: work pygame.display.flip() + + def change_scene(self, scene): + self._scene.exit() + self._scene = scene + self._scene.enter() diff --git a/naja/events.py b/naja/events.py index b2cdee1..ec1b33f 100644 --- a/naja/events.py +++ b/naja/events.py @@ -3,21 +3,22 @@ Custom Pygame events. """ import pygame.event as pge +import pygame.locals as pgl -class NajaEvent(pge.Event): +class NajaEvent(object): TYPE = "UNKNOWN" @classmethod def post(cls, **attributes): - event = pge.Event(pge.USEREVENT, naja_event_type=cls.TYPE, + event = pge.Event(pgl.USEREVENT, naja_event_type=cls.TYPE, **attributes) pge.post(event) @classmethod def matches(cls, ev): - return ev.type == pge.USEREVENT and ev.naja_event_type == cls.TYPE + return ev.type == pgl.USEREVENT and ev.naja_event_type == cls.TYPE class SceneChangeEvent(NajaEvent): diff --git a/naja/scenes/scene.py b/naja/scenes/scene.py index d85dbab..13cafc3 100644 --- a/naja/scenes/scene.py +++ b/naja/scenes/scene.py @@ -12,5 +12,11 @@ class Scene(object): def __init__(self): pass + def enter(self): + pass + + def exit(self): + pass + def handle_event(self): pass -- 2.34.1