diff --git a/app.py b/app.py index d3deffb..0e8691f 100644 --- a/app.py +++ b/app.py @@ -89,6 +89,9 @@ def watekDlaSciezkiAgenta(): agent.rotate_right() if element == "forward": agent.move_direction() + elif isinstance(element, tuple): # Check if it's a tuple indicating movement coordinates + x, y = element + agent.moveto(x, y) time.sleep(1) running = True @@ -132,7 +135,6 @@ while running: watek = threading.Thread(target=watekDlaSciezkiAgenta) watek.daemon = True watek.start() - if pygame.key.get_pressed()[pygame.K_e]: diff --git a/classes/agent.py b/classes/agent.py index 28a8368..b2e1e46 100644 --- a/classes/agent.py +++ b/classes/agent.py @@ -20,6 +20,7 @@ class Agent: self.directionPOM = 0 self.xPOM = 5 self.yPOM = 5 + self.g_scores = {} self.textures = [ pygame.image.load("sprites/BartenderNew64.png").convert_alpha(), @@ -262,6 +263,15 @@ class Agent: return [] #Algorytm astar + def moveto(self,x,y): + if pygame.time.get_ticks()-self.last_move_time > 125 and self.current_cell.X < prefs.GRID_SIZE-1 and not self.cells[x][y].blocking_movement: + self.current_cell = self.cells[x][y] + self.moved=True + self.last_move_time=pygame.time.get_ticks() + print("Agent moved to x,y: ",x,y) + else: + print("Agent cannot move to this direction") + def get_cost(self, cell): x, y = cell[0], cell[1] if x == 0 or x == len(self.cells) - 1 or y == 0 or y == len(self.cells[0]) - 1: @@ -318,10 +328,14 @@ class Agent: heapq.heappush(open_list, (f_score, neighbor_coords)) - return [], float('inf') # If no path found, return an empty path and infinite cost + return [], float('inf') + + + +