Add a 'How To Play' screen
authorNeil <neil@dip.sun.ac.za>
Fri, 16 May 2014 19:33:01 +0000 (21:33 +0200)
committerNeil <neil@dip.sun.ac.za>
Fri, 16 May 2014 19:35:07 +0000 (21:35 +0200)
naja/scenes/howto.py [new file with mode: 0644]
naja/scenes/menu.py

diff --git a/naja/scenes/howto.py b/naja/scenes/howto.py
new file mode 100644 (file)
index 0000000..5114069
--- /dev/null
@@ -0,0 +1,54 @@
+"""
+Howto scene.
+"""
+
+import pygame.locals as pgl
+
+from naja.constants import KEYS
+from naja.scenes.scene import Scene
+from naja.widgets.text import TextWidget, TextBoxWidget
+from naja.events import SceneChangeEvent
+
+
+class HowtoScene(Scene):
+    """
+    Tell the player what to do.
+    """
+
+    def __init__(self, state):
+        super(HowtoScene, self).__init__(state)
+        self.add(TextWidget(
+            (200, 4), 'How To Play the Game', fontsize=32,
+            colour='white'))
+        self.add(TextBoxWidget(
+            (0, 40), '\n'.join([
+                "You are a robot, frantically trying to set the correct "
+                "bits to gain points for reasons that are unlikely to "
+                "ever become clear.",
+                "You have 8 bits. Four bits control the directions "
+                "you can move in {NORTH,SOUTH,EAST,WEST}, 3 allow you "
+                "to unlock actions {RED,GREEN,BLUE} and the "
+                "last, the Most Significant Bit {MSB}, makes everything "
+                "work better.",
+                "MOVEMENT",
+                "During Movement, you can explore the board and learn about "
+                "the available tiles. Tiles you can legally move onto are "
+                "highlighted. It's always possible to stay in place.",
+                "ACTIONS",
+                "After moving, you must select an action. Some actions "
+                "require the correct bits to be set before they can be "
+                "selected. After the action, the tile will be replaced.",
+                "Some actions cost health {HEALTH}. If you run out of "
+                "health {HEALTH}, you lose.",
+                "Some actions gain you points {WINTOKEN}. Once you have "
+                "enough points, you win the game."
+            ]), fontsize=32,
+            colour='white', padding=1, border=1,
+            bg_colour='black', border_colour='black',
+            box_width=400))
+
+    def handle_scene_event(self, ev):
+        from naja.scenes.menu import MenuScene
+        if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
+            SceneChangeEvent.post(MenuScene)
+            return
index 327bb0b371f6222883d9370d68f4e469170fec4a..a94a0edd5e85342429702fbc6f700abf341adf6b 100644 (file)
@@ -9,6 +9,7 @@ from naja.events import SceneChangeEvent, QuitGameEvent
 from naja.scenes.scene import Scene
 from naja.scenes.credits import CreditsScene
 from naja.scenes.game import GameScene
+from naja.scenes.howto import HowtoScene
 from naja.scenes.load_save import LoadGameScene, SaveGameScene
 from naja.scenes.new_game import NewGameScene
 from naja.widgets.selector import SelectorWidget
@@ -48,6 +49,13 @@ class MenuScene(Scene):
         save.set_selectable_callback(lambda: state is not None)
         selector.add(save)
 
+        y_offset += 50
+        howto = TextWidget(
+            (100, y_offset), 'How To Play', fontsize=32, colour='white')
+        howto.add_callback(
+            'click', lambda event: SceneChangeEvent.post(HowtoScene))
+        selector.add(howto)
+
         y_offset += 50
         credits = TextWidget((100, y_offset), 'Credits', colour=PALETTE.WHITE)
         credits.add_callback('click', self.scene_callback(CreditsScene))