From b60ecf8ed1953c64878824c97023bb78e3575459 Mon Sep 17 00:00:00 2001 From: XsedoX Date: Mon, 21 Mar 2022 18:39:28 +0100 Subject: [PATCH] naprawa spawner.py --- logic/game.py | 6 +++++- logic/spawner.py | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/logic/game.py b/logic/game.py index 7f7b129..2a3beee 100644 --- a/logic/game.py +++ b/logic/game.py @@ -87,11 +87,15 @@ class Game: logs = Logs() knight1 = Knight("./resources/textures/knight.png") knight2 = Knight("./resources/textures/knight.png") - spawn = Spawner(grid, [knight1, knight2], 4, 5, 8, 0) + knight3 = Knight("./resources/textures/knight.png") + knight4 = Knight("./resources/textures/knight.png") + spawn = Spawner(grid, [knight1, knight2, knight3, knight4], 4, 5, 8, 0) spawn.spawn() knights_list = pygame.sprite.Group() knights_list.add(knight1) knights_list.add(knight2) + knights_list.add(knight3) + knights_list.add(knight4) while running: self.screen.blit(self.bg, (0, 0)) diff --git a/logic/spawner.py b/logic/spawner.py index fe8322e..ff754c4 100644 --- a/logic/spawner.py +++ b/logic/spawner.py @@ -16,13 +16,13 @@ class Spawner: coords = [] for row in range(self.pos_row, (self.pos_row + self.width)): for column in range(self.pos_column, (self.pos_column + self.height)): - if self.grid.grid[row][column].texture_path != ("water.png" or "grass_with_tree.jpg"): + if self.grid.grid[row][column].texture_path != "water.png" and self.grid.grid[row][column].texture_path != "grass_with_tree.jpg": coords.append([(GRID_CELL_PADDING + GRID_CELL_WIDTH) * column + GRID_CELL_PADDING + 7, (GRID_CELL_PADDING + GRID_CELL_HEIGHT) * row + GRID_CELL_PADDING + 7]) - for obj in self.objs_to_spawn_list: - random_tile = random.randint(0, len(coords) - 1) - obj.rect.x = coords[random_tile][0] - obj.rect.y = coords[random_tile][1] - coords.pop(random_tile) - obj.update() + for obj in self.objs_to_spawn_list: + random_tile = random.randint(0, len(coords) - 1) + obj.rect.x = coords[random_tile][0] + obj.rect.y = coords[random_tile][1] + coords.pop(random_tile) + obj.update()