Scene changing.
authorSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 15:12:42 +0000 (17:12 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sun, 11 May 2014 15:12:42 +0000 (17:12 +0200)
naja/engine.py
naja/events.py
naja/scenes/scene.py

index fc58f18503ddcb0b67754da71d186bf639236a1c..2278fa0e234de3f34aa505f7c206c267eeccbb30 100644 (file)
@@ -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()
index b2cdee1e5a748e614c604af3b5913ff167db1874..ec1b33f154d3cec2491130cc7b623cab85f5dec7 100644 (file)
@@ -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):
index d85dbab5db8937da03e7213a403ea73438cc9b91..13cafc302bbd8f09277c92e982e524e17ab2c559 100644 (file)
@@ -12,5 +12,11 @@ class Scene(object):
     def __init__(self):
         pass
 
+    def enter(self):
+        pass
+
+    def exit(self):
+        pass
+
     def handle_event(self):
         pass