Of course there was a typo.
[naja.git] / naja / scenes / introduction.py
index ddaab48d284096320093ae20983f94705d509658..2d12dd846445bd4e6777120779709cfafbd44686 100644 (file)
@@ -5,7 +5,6 @@ Load and save scenes.
 import pygame.locals as pgl
 import pygame
 
 import pygame.locals as pgl
 import pygame
 
-from naja import constants
 from naja.constants import KEYS, SCREEN, PALETTE
 from naja.events import SceneChangeEvent, LoadGameEvent
 from naja.gamestate import GameState
 from naja.constants import KEYS, SCREEN, PALETTE
 from naja.events import SceneChangeEvent, LoadGameEvent
 from naja.gamestate import GameState
@@ -19,10 +18,13 @@ from naja.resources import resources
 from naja.scenes.dummygame import DummyGameScene
 from naja.widgets.image_box import PreRenderedImageBox
 
 from naja.scenes.dummygame import DummyGameScene
 from naja.widgets.image_box import PreRenderedImageBox
 
+
 class IntroductionScene(Scene):
     def __init__(self, state):
         super(IntroductionScene, self).__init__(state)
 
 class IntroductionScene(Scene):
     def __init__(self, state):
         super(IntroductionScene, self).__init__(state)
 
+        self.grid_surface = None
+
         background = ImageBox(
             (0, 0), "screens/splash.png")
         self.add(background)
         background = ImageBox(
             (0, 0), "screens/splash.png")
         self.add(background)
@@ -77,24 +79,46 @@ class IntroductionScene(Scene):
         self.add(PreRenderedImageBox((0, 0), game_surface))
         return game_surface
 
         self.add(PreRenderedImageBox((0, 0), game_surface))
         return game_surface
 
+    def get_grid_surface(self, game_surface):
+        grid_size = 4
+        if self.grid_surface is None:
+            rect = game_surface.get_rect()
+            size = (rect.width, rect.height)
+            self.grid_surface = pygame.surface.Surface(
+                size, flags=pgl.SRCALPHA)
+            for i in range(0, rect.width, grid_size):
+                for j in range(0, rect.height, grid_size):
+                    if (i + j) % (grid_size * 2) == 0:
+                        continue
+                    pygame.draw.rect(self.grid_surface, PALETTE.GREY,
+                                     (i, j, grid_size, grid_size))
+        return self.grid_surface
+
+    def grid_out(self, game_surface, rect):
+        orig = game_surface.copy()
+        game_surface.blit(self.get_grid_surface(game_surface), (0, 0))
+        game_surface.blit(orig, rect, rect)
+        pygame.draw.rect(game_surface, PALETTE.GREEN, rect, 8)
+
     def introduction_to_screen_1(self, event):
         game_surface = self.make_game_surface()
         self.intro = 1
 
         self.add(TextBoxWidget(
             (24, 72), '\n'.join([
     def introduction_to_screen_1(self, event):
         game_surface = self.make_game_surface()
         self.intro = 1
 
         self.add(TextBoxWidget(
             (24, 72), '\n'.join([
-                "These are your robot's status bits. On the left we have "
-                "the Most Signiticant Bit (MSB, currently set), then Red, "
-                "Green (set) and Blue (set) key bits, and finally the four "
-                "bits which control movement options, of which only left is "
-                "set. You can only move in directions which are set. \n"
+                "These are your robot's status bits. On the left we have"
+                " the Most Significant Bit (MSB, currently set), then the"
+                " Red (unset), Green (set) and Blue (set) key bits, and"
+                " finally the four bits which control movement options, of"
+                " which only left is set. You can only move in directions"
+                " which are set.",
                 "Enter to continue.",
             ]), fontsize=32,
             colour=PALETTE.GREEN, padding=12, border=8,
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
                 "Enter to continue.",
             ]), fontsize=32,
             colour=PALETTE.GREEN, padding=12, border=8,
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
-        pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 0, 480, 60), 8)
+        self.grid_out(game_surface, (0, 0, 480, 60))
 
     def introduction_to_screen_2(self, event):
         game_surface = self.make_game_surface()
 
     def introduction_to_screen_2(self, event):
         game_surface = self.make_game_surface()
@@ -113,7 +137,7 @@ class IntroductionScene(Scene):
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
-        pygame.draw.rect(game_surface, PALETTE.GREEN, (0, 540, 480, 60), 8)
+        self.grid_out(game_surface, (0, 540, 480, 60))
 
     def introduction_to_screen_3(self, event):
         game_surface = self.make_game_surface()
 
     def introduction_to_screen_3(self, event):
         game_surface = self.make_game_surface()
@@ -123,17 +147,17 @@ class IntroductionScene(Scene):
             (24, 132), '\n'.join([
                 "This text box describes the current game mode. The game is "
                 "divided into movements and actions, and each mode has "
             (24, 132), '\n'.join([
                 "This text box describes the current game mode. The game is "
                 "divided into movements and actions, and each mode has "
-                "different options, shown here.\n"
+                "different options, shown here.",
                 "During movement, you can examine the entire board, but you "
                 "During movement, you can examine the entire board, but you "
-                "can only move to hi-lighted tiles (including the one you are "
-                "on. Actions come next... \n"
+                "can only move to highlighted tiles (including the one you"
+                " are on). Actions come next ...",
                 "Enter to continue.",
             ]), fontsize=32,
             colour=PALETTE.GREEN, padding=12, border=8,
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
                 "Enter to continue.",
             ]), fontsize=32,
             colour=PALETTE.GREEN, padding=12, border=8,
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
-        pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 416, 304, 132), 8)
+        self.grid_out(game_surface, (488, 416, 304, 132))
 
     def introduction_to_screen_4(self, event):
         game_surface = self.make_game_surface()
 
     def introduction_to_screen_4(self, event):
         game_surface = self.make_game_surface()
@@ -145,17 +169,16 @@ class IntroductionScene(Scene):
                 "Some actions have requirements and are only selectable if "
                 "you have the correct bits set (unavailable actions are "
                 "greyed out). Actions usually change the bits set on "
                 "Some actions have requirements and are only selectable if "
                 "you have the correct bits set (unavailable actions are "
                 "greyed out). Actions usually change the bits set on "
-                "your robot. This is often not beneficial.\n"
+                "your robot. This is often not beneficial.",
                 "Some actions have additional effects if the MSB is "
                 "Some actions have additional effects if the MSB is "
-                "set.\n"
+                "set.",
                 "Enter to continue.",
             ]), fontsize=32,
             colour=PALETTE.GREEN, padding=12, border=8,
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
                 "Enter to continue.",
             ]), fontsize=32,
             colour=PALETTE.GREEN, padding=12, border=8,
             bg_colour=PALETTE.BLACK, border_colour=PALETTE.GREEN,
             box_width=400, view_port=(500, 800)))
 
-        pygame.draw.rect(game_surface, PALETTE.GREEN, (488, 52, 304, 240), 8)
-
+        self.grid_out(game_surface, (488, 52, 304, 240))
 
     def handle_scene_event(self, ev):
         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
 
     def handle_scene_event(self, ev):
         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT: