From f9c7a9d5b85ec3bdf08f883c1146e1dc889797fa Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sun, 18 May 2014 01:49:56 +0200 Subject: [PATCH] Grid iron. --- naja/scenes/introduction.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/naja/scenes/introduction.py b/naja/scenes/introduction.py index dd161bb..913e2dc 100644 --- a/naja/scenes/introduction.py +++ b/naja/scenes/introduction.py @@ -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: -- 2.34.1