Grid iron.
authorSimon Cross <hodgestar@gmail.com>
Sat, 17 May 2014 23:49:56 +0000 (01:49 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 17 May 2014 23:50:04 +0000 (01:50 +0200)
naja/scenes/introduction.py

index dd161bb32f39411fae45982a519123c3b8b9a847..913e2dcf5468c9f9b08ce68ca3d3a1d4a67caed0 100644 (file)
@@ -23,6 +23,8 @@ 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)
@@ -77,6 +79,27 @@ class IntroductionScene(Scene):
         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
@@ -95,7 +118,7 @@ class IntroductionScene(Scene):
             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()
@@ -114,7 +137,7 @@ class IntroductionScene(Scene):
             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()
@@ -134,7 +157,7 @@ class IntroductionScene(Scene):
             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()
@@ -155,7 +178,7 @@ class IntroductionScene(Scene):
             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: