pawlack

GDScript Dijkistra

Oct 24th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. func player_proximity():
  2.    
  3.     var player_pos
  4.     player_pos = world_to_map(player.get_position())
  5.    
  6.     for x in range(grid_size.x):
  7.         for y in range(grid_size.y):
  8.             player_proximity[x][y] = 990
  9.    
  10.     #Create unexplored set
  11.     var unexplored_set = []
  12.     for x in range(grid_size.x):
  13.         for y in range(grid_size.y):
  14.             if is_cell_not_wall(Vector2(x, y)) == true:
  15.                 unexplored_set.append(Vector2(x, y))
  16.     debug_array = unexplored_set
  17.     player_proximity[player_pos.x][player_pos.y] = 0
  18.    
  19.     #hunt for lowest proximity value
  20.     var current_min = 0
  21.     var AllAdjacentCells = []
  22.     var UnexploredAdjacentCells = []
  23.     var SearchRange = 16
  24.    
  25.     for f in range(SearchRange):
  26.         for x in range(grid_size.x):
  27.             for y in range(grid_size.y):
  28.                 if player_proximity[x][y] == current_min: #&& unexplored_set.has(Vector2(x, y))
  29.                     unexplored_set.erase(Vector2(x, y))
  30.                     print (x, y) #"it's a start" - DmD
  31.                     AllAdjacentCells = get_adjacent_cells(Vector2(x, y))
  32.                     for z in range(AllAdjacentCells.size()):
  33.                         if unexplored_set.has(AllAdjacentCells[z]):
  34.                             UnexploredAdjacentCells.append(AllAdjacentCells[z])
  35.                     #print(UnexploredAdjacentCells)
  36.                     for f in range(UnexploredAdjacentCells.size()):
  37.                         player_proximity[(UnexploredAdjacentCells[f].x)][UnexploredAdjacentCells[f].y] = current_min+1
  38.                         unexplored_set.erase(Vector2(UnexploredAdjacentCells[f].x, UnexploredAdjacentCells[f].y))
  39.         current_min += 1
  40.         AllAdjacentCells.clear()
  41.         UnexploredAdjacentCells.clear()
  42.    
  43.    
  44.    
  45.     #print(player_proximity.min())
  46.     #print(unexplored_set)
  47.        
  48.        
  49.     pass
Advertisement
Add Comment
Please, Sign In to add comment