Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1.         //List of coords need to check.
  2.         List<Coord> scanCoords = new ArrayList<Coord>();
  3.         //List of coords already mapped.
  4.         List<Coord> grave = new ArrayList<Coord>();
  5.         //Add starting coord to scan list.
  6.         scanCoords.add(new Coord(x, y));
  7.        
  8.         //Iterator
  9.         ListIterator<Coord> coord = scanCoords.listIterator();
  10.         while(coord.hasNext()){
  11.             //Current x, y.
  12.             Coord c = coord.next();
  13.             int yb = c.getY();
  14.             int xb = c.getX();
  15.            
  16.             //Loop over tiles all around xb,yb except for themselves.
  17.             for(int ya = yb - 1; ya < yb + 1; ya++){
  18.                 for(int xa = xb - 1; xa < xb + 1; xa++){
  19.                     //If xa,ya out of bounds continue.
  20.                     if(xa < 0 || ya < 0 || xa >= width || ya >= height) continue;
  21.                     //If looped over starting coords, ignore.
  22.                     if(xa == xb && ya == yb) continue;
  23.                     //If xa,ya is not land tile, ignore.
  24.                     if(tempId[xa + ya * width] != 0) continue;
  25.                     //If current island already has tile mapped, ignore.
  26.                     if(i.contains(xa, ya)) continue;
  27.                     //If tile has already been mapped ignore.
  28.                     if(grave.contains(new Coord(xa, ya))) continue;
  29.  
  30.                     //Add new coord to scan list.
  31.                     scanCoords.add(new Coord(xa, ya));
  32.                     //Add new coord to island tiles.
  33.                     i.coords.add(new Coord(xa, ya));
  34.                    
  35.                 }
  36.             }
  37.             //Add starting point to grave
  38.             grave.add(new Coord(xb, yb));
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement