Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //List of coords need to check.
- List<Coord> scanCoords = new ArrayList<Coord>();
- //List of coords already mapped.
- List<Coord> grave = new ArrayList<Coord>();
- //Add starting coord to scan list.
- scanCoords.add(new Coord(x, y));
- //Iterator
- ListIterator<Coord> coord = scanCoords.listIterator();
- while(coord.hasNext()){
- //Current x, y.
- Coord c = coord.next();
- int yb = c.getY();
- int xb = c.getX();
- //Loop over tiles all around xb,yb except for themselves.
- for(int ya = yb - 1; ya < yb + 1; ya++){
- for(int xa = xb - 1; xa < xb + 1; xa++){
- //If xa,ya out of bounds continue.
- if(xa < 0 || ya < 0 || xa >= width || ya >= height) continue;
- //If looped over starting coords, ignore.
- if(xa == xb && ya == yb) continue;
- //If xa,ya is not land tile, ignore.
- if(tempId[xa + ya * width] != 0) continue;
- //If current island already has tile mapped, ignore.
- if(i.contains(xa, ya)) continue;
- //If tile has already been mapped ignore.
- if(grave.contains(new Coord(xa, ya))) continue;
- //Add new coord to scan list.
- scanCoords.add(new Coord(xa, ya));
- //Add new coord to island tiles.
- i.coords.add(new Coord(xa, ya));
- }
- }
- //Add starting point to grave
- grave.add(new Coord(xb, yb));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement