fix: agent moving astar (still (x,y))
This commit is contained in:
parent
d130f2360b
commit
713a1e6679
4
app.py
4
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
|
||||
@ -134,7 +137,6 @@ while running:
|
||||
watek.start()
|
||||
|
||||
|
||||
|
||||
if pygame.key.get_pressed()[pygame.K_e]:
|
||||
if agent.current_cell.interactableItem and pygame.time.get_ticks() - agent.last_interact_time > 500:
|
||||
agent.last_interact_time = pygame.time.get_ticks()
|
||||
|
@ -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,7 +328,11 @@ 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')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user