Advertisement
Guest User

Untitled

a guest
Sep 14th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // start by creating an array the same size as the map (or a field in the map udt) . I'm assuming here the map is 32x32.
  2.  
  3. h = 24
  4. w = 24
  5. int pathing[h,w];
  6.  
  7. // create a doneflag to record when a search pass didn't do anthing. initialise to zero to make a first pass.
  8. int doneflag = 0;
  9.  
  10. // set all elements to a large value, like 256.
  11. for(xx=0; xx<w; xx++) {
  12.   for(yy=0; yy<h; yy++) {
  13.     pathing[xx,yy] = 256;
  14.   }
  15. }
  16.  
  17. // set the element where the player is to 0.
  18. pathing[player.x/8, player.y/8] = 0;
  19.  
  20. // loop while there are still passes to do.
  21. while (doneflag == 0) {
  22.  
  23. // set a doneflag to 1 to say we are done.
  24. doneflag = 1;
  25.  
  26. // start a double loop through x and y.
  27. for(xx=0; xx<w; xx++) {
  28.   for(yy=0; yy<h; yy++) {
  29.  
  30.  
  31. // if you find an element with value < 256 then look at four neighbours. if any of those is a floor tile, AND has value 256 then set it equal to value+1.
  32.  
  33.      if(pathing[xx,yy] < 256) {
  34.        if(pathing[xx-1,yy] == 256 && ds_grid_get(global.mainGrid,xx,yy) = 0)  {pathing[xx-1,yy]=pathing[xx,yy]+1; doneflag=0;}
  35.        if(pathing[xx+1,yy] == 256 && ds_grid_get(global.mainGrid,xx+1,yy) = 0) {pathing[xx+1,yy]=pathing[xx,yy]+1; doneflag=0;}
  36.        if(pathing[xx,yy-1] == 256 && ds_grid_get(global.mainGrid,xx,yy-1) = 0) {pathing[xx,yy-1]=pathing[xx,yy]+1; doneflag=0;}
  37.        if(pathing[xx,yy+1] == 256 && ds_grid_get(global.mainGrid,xx,yy+1) = 0) {pathing[xx,yy+1]=pathing[xx,yy]+1; doneflag=0;}
  38.         }
  39. // close the double loop
  40.     }
  41. }
  42.  
  43. //close while
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement