From: David Sharpe Date: Sun, 11 May 2014 16:30:02 +0000 (+0200) Subject: Added basic credits scene. X-Git-Tag: 0.1~414 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=f9df3168bbc287159a2ff42a6c2ba3cacdc7e706;p=naja.git Added basic credits scene. --- diff --git a/naja/engine.py b/naja/engine.py index 1c6b70a..3565f4b 100644 --- a/naja/engine.py +++ b/naja/engine.py @@ -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 index 0000000..cd3ad58 --- /dev/null +++ b/naja/scenes/credits.py @@ -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 diff --git a/naja/scenes/menu.py b/naja/scenes/menu.py index 822c87a..a72beff 100644 --- a/naja/scenes/menu.py +++ b/naja/scenes/menu.py @@ -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