From b5e8c047548d3c16cd47f1ff0f577bb37bb84329 Mon Sep 17 00:00:00 2001 From: Miguel Angel Astor Romero Date: Wed, 16 Jan 2013 23:53:32 -0430 Subject: [PATCH] Changed tiled background to work based on repetitions. --- background.py | 9 ++++----- ingame.py | 17 +++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/background.py b/background.py index 77dcf8a..c1613e1 100644 --- a/background.py +++ b/background.py @@ -6,17 +6,16 @@ import pygame import imloader from constants import DEBUG class TiledBackground(): - def __init__(self, width, height, texture_filename, position_x = 0, position_y = 0): - self.w = width - self.h = height + def __init__(self, rep_x, rep_y, texture_filename, position_x = 0, position_y = 0): self.position = (position_x, position_y) texture = imloader.cached_image_loader.get_image_to_screen_percent(texture_filename) img_w = texture.get_width() img_h = texture.get_height() - rep_x = (self.w // img_w) + 1 - rep_y = (self.h // img_h) + 1 + self.w = img_w * rep_x + self.h = img_h * rep_y + if DEBUG: print '(' + str(rep_x) + ', ' + str(rep_y) + ')' diff --git a/ingame.py b/ingame.py index 0a88d27..06426b4 100644 --- a/ingame.py +++ b/ingame.py @@ -32,22 +32,19 @@ class InGameState(BaseState): self.background = pygame.Surface((bg_w, bg_h)) # Create the floor. - floor = background.TiledBackground(bg_w, bg_h, 'gfx/piso.png') + floor = background.TiledBackground(20, 16, 'gfx/piso.png') # Create the walls for the top and the bottom (the same for both). - bg_h = int((80.0 * float(pygame.display.Info().current_h)) / 768.0) - walls_top = background.TiledBackground(bg_w, bg_h, 'gfx/Pared.png') + walls_top = background.TiledBackground(15, 1, 'gfx/Pared.png') bg_y = int(((1024.0 - 80.0) * float(pygame.display.Info().current_h)) / 768.0) # Create the left walls. - bg_w = int((40.0 * float(pygame.display.Info().current_w)) / 1024.0) - bg_h = int(((1024.0 - 160) * float(pygame.display.Info().current_h)) / 768.0) - walls_left = background.TiledBackground(bg_w, bg_h, 'gfx/Pared2.png') + walls_left = background.TiledBackground(1, 12, 'gfx/Pared2.png') _y = int((80.0 * float(pygame.display.Info().current_h)) / 768.0) walls_left.set_position((0, _y)) # Create the right walls. - walls_right = background.TiledBackground(bg_w, bg_h, 'gfx/Pared3.png') + walls_right = background.TiledBackground(1, 12, 'gfx/Pared3.png') _x = int(((1280.0 - 40.0) * float(pygame.display.Info().current_h)) / 768.0) walls_right.set_position((_x, _y)) @@ -55,10 +52,10 @@ class InGameState(BaseState): floor.draw(self.background) walls_top.set_position((0, 0)) walls_top.draw(self.background) - walls_top.set_position((0, bg_y)) - walls_top.draw(self.background) walls_left.draw(self.background) walls_right.draw(self.background) + walls_top.set_position((0, bg_y)) + walls_top.draw(self.background) def input(self): for event in pygame.event.get(): @@ -91,5 +88,5 @@ class InGameState(BaseState): def render(self, canvas): canvas.fill(self.background_color) - canvas.blit(self.background, (0, 0)) + canvas.blit(self.background, (0, -1024 / 2)) pygame.draw.rect(canvas, (255, 0, 255), self.rectangle)