Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // start by creating a array the same size as the map (or a field in the map udt)
- int pathing[32,32];
- //create a counter c initialised to zero.
- int c = 0;
- // create a flag to record when a search pass didn't do anthing. initialise to zero to make a first pass.
- int flag = 0;
- // set all elements to a large value, like 256.
- for(x=0; x<32; x++) {
- for(y=0; y<32; y++) {
- pathing[x,y] = 256;
- }
- }
- // set the element where the player is to c.
- pathing[player.x, player.y] = c;
- // loop while there are still passes to do.
- while (flag == 0)
- // set a flag to 1 to say we are done.
- flag = 1;
- // start a double loop through x and y.
- for(x=0; x<32; x++) {
- for(y=0; y<32; y++) {
- // 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.
- if(pathing[x,y] == c) {
- if(pathing[x-1,y] == 256 && map[x-1,y] == floor) {pathing[x-1,y]=c+1; flag=0;}
- if(pathing[x+1,y] == 256 && map[x+1,y] == floor) {pathing[x+1,y]=c+1; flag=0;}
- if(pathing[x,y-1] == 256 && map[x,y-1] == floor) {pathing[x,y-1]=c+1; flag=0;}
- if(pathing[x,y+1] == 256 && map[x,y+1] == floor) {pathing[x,y+1]=c+1; flag=0;}
- }
- // close the double loop
- }
- }
- // increment counter for next pass
- c++;
- //close while
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement