def main(): global window, origin, astar, objective window = pygame.display.set_mode(WINDOW_SIZE) pygame.display.set_caption("A* Pathfinding") gen_rects() origin = grid_list[3][5] objective = grid_list[12][28] astar = AStar(origin, objective) gen_objective_distance() gen_adjacents() loop = True start = False vel = 30 while loop: window.fill(WHITE) #events for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: start = True if event.type == pygame.MOUSEBUTTONUP: if pygame.mouse.get_pressed(3)[0]: click_wall(pygame.mouse.get_pos(), True) if pygame.mouse.get_pressed(3)[2]: click_wall(pygame.mouse.get_pos(), False) if event.type == pygame.MOUSEMOTION: if pygame.mouse.get_pressed(3)[0]: click_wall(pygame.mouse.get_pos(), True) if pygame.mouse.get_pressed(3)[2]: click_wall(pygame.mouse.get_pos(), False) if start: vel = 5 if not astar.found: astar.seach() pygame.draw.rect(window, RED, objective.rect) pygame.draw.rect(window, GREEN, origin.rect) draw_grid() # if astar.found: # back(vel,astar) # astar.seach_back() # for sqr in astar.path: # pygame.draw.rect(window,BLUE,sqr.rect) pygame.display.update() fps.tick(vel)