diff --git a/app.py b/app.py index d383bc0..40bb5c1 100644 --- a/app.py +++ b/app.py @@ -98,15 +98,26 @@ else: print("Brak sciezki") +#oddaje tablice punktow jako sciezke agenta +def convert_to_coordinates(shortest_path): + coordinates = [(cell.X, cell.Y) for cell in shortest_path] + return coordinates + +path = convert_to_coordinates(shortest_path) - - - - +#Wyjmuje pierwsze koordynaty do ruszenia agenta a potem usuwa je z listy +def pop_first_coordinates(coordinates): + if coordinates: + x, y = coordinates.pop(0) + return x, y + else: + print("Lista współrzędnych jest pusta.") + return None, None agent = Agent(prefs.SPAWN_POINT[0], prefs.SPAWN_POINT[1], cells) + running = True while running: for event in pygame.event.get(): @@ -132,6 +143,14 @@ while running: agent.current_cell.interactableItem.interact(agent) + + if not agent.moved: + first_x, first_y = pop_first_coordinates(path) + if first_x is not None and first_y is not None: + agent.moveto(first_x,first_y) + + + window.fill((255, 0, 0)) draw_grid(window, cells, agent) agent.update(window) diff --git a/classes/agent.py b/classes/agent.py index 7dac049..68538cc 100644 --- a/classes/agent.py +++ b/classes/agent.py @@ -64,3 +64,12 @@ class Agent: if self.multiplier < 1: self.multiplier = 1 + 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") +