Advertisement
Sorceress

Untitled

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