[integrate_a_star_and_movement] little fixes
This commit is contained in:
parent
e6448b61cd
commit
37375d4f1d
1
main.py
1
main.py
@ -127,6 +127,7 @@ class Game():
|
|||||||
clicked_coords = [math.floor(pos[0] / TILESIZE) - offset_x, math.floor(pos[1] / TILESIZE) - offset_y]
|
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)
|
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)
|
print(actions)
|
||||||
|
if (actions != None):
|
||||||
t = aiPlayer.aiPlayer(self.player, game=self)
|
t = aiPlayer.aiPlayer(self.player, game=self)
|
||||||
t.startAiController(actions)
|
t.startAiController(actions)
|
||||||
|
|
||||||
|
18
map/map.py
18
map/map.py
@ -4,17 +4,17 @@ import pygame as pg
|
|||||||
from settings import *
|
from settings import *
|
||||||
|
|
||||||
def get_tiles():
|
def get_tiles():
|
||||||
# array = map_utils.generate_map()
|
array = map_utils.generate_map()
|
||||||
array = map_utils.get_blank_map_array()
|
# array = map_utils.get_blank_map_array()
|
||||||
|
|
||||||
array[1][1] = 1
|
# array[1][1] = 1
|
||||||
array[1][2] = 1
|
# array[1][2] = 1
|
||||||
array[1][3] = 1
|
# array[1][3] = 1
|
||||||
array[1][4] = 1
|
# array[1][4] = 1
|
||||||
array[1][5] = 1
|
# array[1][5] = 1
|
||||||
array[1][6] = 1
|
# array[1][6] = 1
|
||||||
|
|
||||||
array[2][5] = 1
|
# array[2][5] = 1
|
||||||
|
|
||||||
pattern = map_pattern.get_pattern()
|
pattern = map_pattern.get_pattern()
|
||||||
tiles = map_utils.get_sprites(array, pattern)
|
tiles = map_utils.get_sprites(array, pattern)
|
||||||
|
@ -26,7 +26,7 @@ class Node:
|
|||||||
def f_cost(self):
|
def f_cost(self):
|
||||||
return self.g_cost + self.h_cost
|
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 = []
|
neighbours = []
|
||||||
for offset_x in range (-1, 2):
|
for offset_x in range (-1, 2):
|
||||||
for offset_y 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
|
x = node.x + offset_x
|
||||||
y = node.y + offset_y
|
y = node.y + offset_y
|
||||||
# prevent out of map coords
|
# 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):
|
if(array[y][x] == ROAD_TILE and (x, y) not in searched_list):
|
||||||
neighbour = Node(x, y, Rotation.NONE)
|
neighbour = Node(x, y, Rotation.NONE)
|
||||||
neighbour.rotation = get_needed_rotation(node, neighbour)
|
neighbour.rotation = get_needed_rotation(node, neighbour)
|
||||||
|
@ -27,8 +27,8 @@ PLAYER_WIDTH = 64
|
|||||||
PLAYER_HEIGHT = 32
|
PLAYER_HEIGHT = 32
|
||||||
|
|
||||||
#map settings
|
#map settings
|
||||||
MAP_WIDTH = 20
|
MAP_WIDTH = 16
|
||||||
MAP_HEIGHT = 20
|
MAP_HEIGHT = 12
|
||||||
|
|
||||||
TILE_SIZE_PX = 64
|
TILE_SIZE_PX = 64
|
||||||
MAP_WIDTH_PX = MAP_WIDTH * TILE_SIZE_PX
|
MAP_WIDTH_PX = MAP_WIDTH * TILE_SIZE_PX
|
||||||
|
Loading…
Reference in New Issue
Block a user