View difference between Paste ID: 8q86BZLU and asCW3cw6
SHOW: | | - or go back to the newest paste.
 1 - ```// start by creating a array the same size as the map (or a field in the map udt) ``` 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 ```int pathing[32,32]; ``` 4 5 - ```//create a counter c initialised to zero. ``` 5 + 6 - ```int c = 0; ``` 6 + ```// create a doneflag to record when a search pass didn't do anthing. initialise to zero to make a first pass. ``` 7 ```int doneflag = 0; ``` 8 - ```// create a flag to record when a search pass didn't do anthing. initialise to zero to make a first pass. ``` 8 + 9 - ```int flag = 0; ``` 9 + 10 ```for(x=0; x<32; x++) { ``` 11 ``` for(y=0; y<32; y++) { ``` 12 ``` pathing[x,y] = 256; ``` 13 ``` } ``` 14 ```} ``` 15 16 ```// set the element where the player is to 0. ``` 17 ```pathing[player.x, player.y] = 0; ``` 18 - ```// set the element where the player is to c. ``` 18 + 19 - ```pathing[player.x, player.y] = c; ``` 19 + 20 ```while (doneflag == 0) ``` 21 22 - ```while (flag == 0) ``` 22 + ```// set a doneflag to 1 to say we are done. ``` 23 ```doneflag = 1; ``` 24 - ```// set a flag to 1 to say we are done. ``` 24 + 25 - ```flag = 1; ``` 25 + 26 ```for(x=0; x<32; x++) { ``` 27 ``` for(y=0; y<32; y++) { ``` 28 29 30 ```// 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. ``` 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. ``` 32 + ``` if(pathing[x,y] < 256) { ``` 33 ``` if(pathing[x-1,y] == 256 && map[x-1,y] == floor) {pathing[x-1,y]=pathing[x,y]+1; doneflag=0;} ``` 34 - ``` if(pathing[x,y] == c) { ``` 34 + ``` if(pathing[x+1,y] == 256 && map[x+1,y] == floor) {pathing[x+1,y]=pathing[x,y]+1; doneflag=0;} ``` 35 - ``` if(pathing[x-1,y] == 256 && map[x-1,y] == floor) {pathing[x-1,y]=c+1; flag=0;} ``` 35 + ``` if(pathing[x,y-1] == 256 && map[x,y-1] == floor) {pathing[x,y-1]=pathing[x,y]+1; doneflag=0;} ``` 36 - ``` if(pathing[x+1,y] == 256 && map[x+1,y] == floor) {pathing[x+1,y]=c+1; flag=0;} ``` 36 + ``` if(pathing[x,y+1] == 256 && map[x,y+1] == floor) {pathing[x,y+1]=pathing[x,y]+1; doneflag=0;} ``` 37 - ``` if(pathing[x,y-1] == 256 && map[x,y-1] == floor) {pathing[x,y-1]=c+1; flag=0;} ``` 37 + 38 - ``` if(pathing[x,y+1] == 256 && map[x,y+1] == floor) {pathing[x,y+1]=c+1; flag=0;} ``` 38 + 39 ```// close the double loop ``` 40 ```} ``` 41 ```} ``` 42 43 ```//close while ``` 44 `}`