Added basic credits scene.
authorDavid Sharpe <decoydavid@gmail.com>
Sun, 11 May 2014 16:30:02 +0000 (18:30 +0200)
committerDavid Sharpe <decoydavid@gmail.com>
Sun, 11 May 2014 16:30:02 +0000 (18:30 +0200)
naja/engine.py
naja/scenes/credits.py [new file with mode: 0644]
naja/scenes/menu.py

index 1c6b70ac8a7917871edae10512acfc90e11b80d2..3565f4be0652d5d388f4b42d607c029c33315a2c 100644 (file)
@@ -20,6 +20,7 @@ class Engine(object):
                 elif SceneChangeEvent.matches(ev):
                     self.change_scene(ev.scene)
                 else:
+                    print(ev.type)
                     self._scene.handle_event(ev)
             self._scene.render(self._surface)
             pygame.display.flip()
diff --git a/naja/scenes/credits.py b/naja/scenes/credits.py
new file mode 100644 (file)
index 0000000..cd3ad58
--- /dev/null
@@ -0,0 +1,27 @@
+"""
+Main menu scene.
+"""
+
+import pygame.locals as pgl
+
+from naja.scenes.scene import Scene
+from naja.widgets.text import TextWidget
+from naja.events import SceneChangeEvent
+
+
+class CreditsScene(Scene):
+
+    base_menu = None
+
+    def __init__(self):
+        super(CreditsScene, self).__init__()
+        self.widgets.append(TextWidget((10, 10), 'Credits',
+                            colour=(255, 255, 255)))
+
+    def set_base_menu(self, base_menu):
+        self.base_menu = base_menu
+
+    def handle_event(self, ev):
+        if ev.type == pgl.KEYUP and ev.key in (pgl.K_q, pgl.K_ESCAPE):
+            SceneChangeEvent.post(self.base_menu)
+            return
index 822c87a1eb77db35d98b965694c3aff81e7b4dae..a72beff4dd25dceee62a291c005d6654a4bf73fc 100644 (file)
@@ -7,16 +7,22 @@ import pygame.locals as pgl
 from naja.scenes.scene import Scene
 from naja.widgets.text import TextWidget
 from naja.events import QuitGameEvent
-
+from naja.scenes.credits import CreditsScene
+from naja.events import SceneChangeEvent
 
 class MenuScene(Scene):
 
     def __init__(self):
         super(MenuScene, self).__init__()
-        self.widgets.append(TextWidget((10, 10), 'Haai',
+        self.widgets.append(TextWidget((10, 10), 'Naja',
                             colour=(255, 255, 255)))
+        self.credits_menu = CreditsScene()
+        self.credits_menu.set_base_menu(self)
 
     def handle_event(self, ev):
         if ev.type == pgl.KEYUP and ev.key in (pgl.K_q, pgl.K_ESCAPE):
             QuitGameEvent.post()
             return
+        if ev.type == pgl.KEYUP and ev.key is pgl.K_RETURN:
+            SceneChangeEvent.post(self.credits_menu)
+            return