diff --git a/field.py b/field.py new file mode 100644 index 0000000..111c999 --- /dev/null +++ b/field.py @@ -0,0 +1,4 @@ +class Field: + def __init__(self, texture_path, converted_texture): + self.texture_path = texture_path + self.converted_texture = converted_texture diff --git a/game.py b/game.py index b375423..54ae33e 100644 --- a/game.py +++ b/game.py @@ -1,4 +1,7 @@ import pygame +from glob import glob + +from grid import Grid GAME_TITLE = 'WMICraft' WINDOW_HEIGHT = 900 @@ -17,25 +20,23 @@ class Game: pygame.init() pygame.display.set_caption(GAME_TITLE) pygame.display.set_icon(pygame.image.load('resources/icons/sword.png')) + self.screen = pygame.display.set_mode((WINDOW_HEIGHT, WINDOW_WIDTH)) self.clock = pygame.time.Clock() + self.textures = [] + for texture_path in glob('resources/textures/*.jpg'): + converted_texture = pygame.image.load(texture_path).convert_alpha() + self.textures.append((texture_path, converted_texture)) + def start(self): running = True + grid = Grid(self.textures) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False - self.draw_grid() + grid.draw(self.screen) pygame.display.update() self.clock.tick(FPS_COUNT) pygame.quit() - - def draw_grid(self): - for row in range(ROWS): - for column in range(COLUMNS): - box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING, - (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING, - GRID_CELL_WIDTH, - GRID_CELL_HEIGHT] - pygame.draw.rect(self.screen, GREEN, box_rect) diff --git a/grid.py b/grid.py new file mode 100644 index 0000000..285bd22 --- /dev/null +++ b/grid.py @@ -0,0 +1,35 @@ +import pygame +import random +from field import Field + +GRID_CELL_PADDING = 3 +GRID_CELL_WIDTH = 42 +GRID_CELL_HEIGHT = 42 +ROWS = 20 +COLUMNS = 20 + + +class Grid: + def __init__(self, textures): + self.textures = textures + self.grid = [] + for row in range(ROWS): + self.grid.append([]) + for _ in range(COLUMNS): + texture_path, converted_texture = self.get_random_texture() + field = Field(texture_path, converted_texture) + self.grid[row].append(field) + + def get_random_texture(self): + texture_index = random.randint(0, len(self.textures) - 1) + return self.textures[texture_index] + + def draw(self, screen): + for row in range(ROWS): + for column in range(COLUMNS): + box_rect = [(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING, + (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING, + GRID_CELL_WIDTH, + GRID_CELL_HEIGHT] + image = self.grid[row][column].converted_texture + screen.blit(pygame.transform.scale(image, (GRID_CELL_WIDTH, GRID_CELL_HEIGHT)), box_rect) diff --git a/resources/textures/t1.jpeg b/resources/textures/t1.jpeg new file mode 100644 index 0000000..9a0887f Binary files /dev/null and b/resources/textures/t1.jpeg differ diff --git a/resources/textures/t10.jpg b/resources/textures/t10.jpg new file mode 100644 index 0000000..7b37316 Binary files /dev/null and b/resources/textures/t10.jpg differ diff --git a/resources/textures/t2.jpg b/resources/textures/t2.jpg new file mode 100644 index 0000000..b8ecd88 Binary files /dev/null and b/resources/textures/t2.jpg differ diff --git a/resources/textures/t3.jpg b/resources/textures/t3.jpg new file mode 100644 index 0000000..5a5cde1 Binary files /dev/null and b/resources/textures/t3.jpg differ diff --git a/resources/textures/t4.jpg b/resources/textures/t4.jpg new file mode 100644 index 0000000..ed0f42c Binary files /dev/null and b/resources/textures/t4.jpg differ diff --git a/resources/textures/t5.jpg b/resources/textures/t5.jpg new file mode 100644 index 0000000..4d32bfd Binary files /dev/null and b/resources/textures/t5.jpg differ diff --git a/resources/textures/t6.jpg b/resources/textures/t6.jpg new file mode 100644 index 0000000..8c50677 Binary files /dev/null and b/resources/textures/t6.jpg differ diff --git a/resources/textures/t7.jpg b/resources/textures/t7.jpg new file mode 100644 index 0000000..129c1d8 Binary files /dev/null and b/resources/textures/t7.jpg differ diff --git a/resources/textures/t8.jpg b/resources/textures/t8.jpg new file mode 100644 index 0000000..bde20cf Binary files /dev/null and b/resources/textures/t8.jpg differ diff --git a/resources/textures/t9.jpg b/resources/textures/t9.jpg new file mode 100644 index 0000000..088a355 Binary files /dev/null and b/resources/textures/t9.jpg differ