From: Simon Cross Date: Sun, 11 May 2014 15:12:42 +0000 (+0200) Subject: Scene changing. X-Git-Tag: 0.1~426 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=9959d703e59a5baa3aaad6fd3d5de88385f7c3e0;p=naja.git Scene changing. --- 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