import pygame
import pygame.locals as pgl
+from naja.events import SceneChangeEvent
+
class Engine(object):
def __init__(self, surface, scene):
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()
"""
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):