diff --git a/main.py b/main.py index 5410883..598f5b4 100644 --- a/main.py +++ b/main.py @@ -127,8 +127,9 @@ class Game(): clicked_coords = [math.floor(pos[0] / TILESIZE) - offset_x, math.floor(pos[1] / TILESIZE) - offset_y] actions = a_star.search_path(math.floor(self.player.pos[0] / TILESIZE), math.floor(self.player.pos[1] / TILESIZE), self.player.rotation(), clicked_coords[0], clicked_coords[1], self.mapArray) print(actions) - t = aiPlayer.aiPlayer(self.player, game=self) - t.startAiController(actions) + if (actions != None): + t = aiPlayer.aiPlayer(self.player, game=self) + t.startAiController(actions) def show_start_screen(self): pass diff --git a/map/map.py b/map/map.py index fa26b71..b4c332c 100644 --- a/map/map.py +++ b/map/map.py @@ -4,17 +4,17 @@ import pygame as pg from settings import * def get_tiles(): - # array = map_utils.generate_map() - array = map_utils.get_blank_map_array() + array = map_utils.generate_map() + # array = map_utils.get_blank_map_array() - array[1][1] = 1 - array[1][2] = 1 - array[1][3] = 1 - array[1][4] = 1 - array[1][5] = 1 - array[1][6] = 1 + # array[1][1] = 1 + # array[1][2] = 1 + # array[1][3] = 1 + # array[1][4] = 1 + # array[1][5] = 1 + # array[1][6] = 1 - array[2][5] = 1 + # array[2][5] = 1 pattern = map_pattern.get_pattern() tiles = map_utils.get_sprites(array, pattern) diff --git a/path_search_algorthms/a_star_utils.py b/path_search_algorthms/a_star_utils.py index b757be6..c0f98ce 100644 --- a/path_search_algorthms/a_star_utils.py +++ b/path_search_algorthms/a_star_utils.py @@ -26,7 +26,7 @@ class Node: def f_cost(self): return self.g_cost + self.h_cost -def get_neighbours(node: Node, searched_list: list[Node], array: list[list[int]]) -> list[Node]: +def get_neighbours(node: 'Node', searched_list: list['Node'], array: list[list[int]]) -> list['Node']: neighbours = [] for offset_x in range (-1, 2): for offset_y in range (-1, 2): @@ -35,7 +35,7 @@ def get_neighbours(node: Node, searched_list: list[Node], array: list[list[int]] x = node.x + offset_x y = node.y + offset_y # prevent out of map coords - if (x >= 0 and x <= MAP_WIDTH and y >= 0 and y <= MAP_HEIGHT): + if (x >= 0 and x < MAP_WIDTH and y >= 0 and y < MAP_HEIGHT): if(array[y][x] == ROAD_TILE and (x, y) not in searched_list): neighbour = Node(x, y, Rotation.NONE) neighbour.rotation = get_needed_rotation(node, neighbour) diff --git a/settings.py b/settings.py index 6bb0ab2..72c250a 100644 --- a/settings.py +++ b/settings.py @@ -27,8 +27,8 @@ PLAYER_WIDTH = 64 PLAYER_HEIGHT = 32 #map settings -MAP_WIDTH = 20 -MAP_HEIGHT = 20 +MAP_WIDTH = 16 +MAP_HEIGHT = 12 TILE_SIZE_PX = 64 MAP_WIDTH_PX = MAP_WIDTH * TILE_SIZE_PX