diff --git a/triple-dungeon/main.py b/triple-dungeon/main.py index fc897a4..05829d1 100644 --- a/triple-dungeon/main.py +++ b/triple-dungeon/main.py @@ -121,7 +121,11 @@ class Game(arcade.Window): # Draw paths for all mobs for mob in self.enemy_list: if mob.target is not None: - self.draw_path(mob.get_path()) + t1 = time.time() + path = mob.get_path() + t2 = time.time() + print(f'Path acquired in {round(t2 - t1, 4)}s') + self.draw_path(path) self.fps.tick() except Exception: @@ -136,9 +140,10 @@ class Game(arcade.Window): """ if len(path) > 2: - path = map(lambda point: ((0.5 + point[0]) * Config.TILE_SIZE, (0.5 + point[1]) * Config.TILE_SIZE), path) - arcade.draw_lines(list(path)) - # for pos1, pos2 in zip(path, path[1:]) + path = map(lambda point: ((point[0]) * Config.TILE_SIZE, (point[1]) * Config.TILE_SIZE), path) + path = list(path) + for pos1, pos2 in zip(path, path[1:]): + arcade.draw_line(*pos1, *pos2, color=arcade.color.RED) def on_key_press(self, key, modifiers): """Called whenever a key is pressed. """ diff --git a/triple-dungeon/map.py b/triple-dungeon/map.py index 7803d67..32f254e 100644 --- a/triple-dungeon/map.py +++ b/triple-dungeon/map.py @@ -45,16 +45,16 @@ class Dungeon(object): self.levels = [ [Level.load_file(x, y, center) for y in range(size)] for x in range(size) ] - self.matrix = [[0 for yy in range(size * 10)] for xx in range(10 * size)] + self.matrix = [[1 for yy in range(size * 10)] for xx in range(10 * size)] for column in self.levels: for level in column: for xx in range(10): for yy in range(10): if level.structure[xx][yy] == 'w': - self.matrix[(level.x * 10) + xx][(level.y * 10) + yy] = 1 + self.matrix[(level.x * 10) + xx][(level.y * 10) + yy] = 0 self.grid = Grid(matrix=self.matrix) self.finder = AStarFinder(diagonal_movement=DiagonalMovement.always) - # pprint(self.matrix, width=1000) + pprint(self.matrix, width=1000) def getWalls(self) -> arcade.SpriteList: """ diff --git a/triple-dungeon/mobs.py b/triple-dungeon/mobs.py index 4e50815..aba6ac2 100644 --- a/triple-dungeon/mobs.py +++ b/triple-dungeon/mobs.py @@ -56,10 +56,9 @@ class Mob(arcade.Sprite): if end is None: end = self.target.position start, end = self.nearestPosition(), (round(end[0] / Config.TILE_SIZE), round(end[1] / Config.TILE_SIZE)) - print(start, end) start, end = self.dungeon.grid.node(*start), self.dungeon.grid.node(*end) paths, runs = self.dungeon.finder.find_path(start, end, self.dungeon.grid) - print(paths, runs) + self.dungeon.grid.cleanup() return paths