Map Generation 2.0

Further development into the map generation, now I included dynamic change of size and now the tiles check if at least adjacent tiles are right to be there, if not a random park its placed (the double cross tile). Also included a grass texture into the tiles.

To achieve that before instantiating the tiles I created a new function that is called after the array of numbers is created, this function checks for each neighbor (up, down, left and right tiles) if it make sense that this tile appears in that position. The critical tiles are the straight vertical or horizontal lines because it can happen that it does not connect with anything. In that case if these exception is found the function substitutes the number with a new one (the park one). The tiles that are in the borders of the square are not checked.

This is the code  to check if any vertical road has no right neighbors:

//vertical road
if (tileArray [i, j] == 1) {

          if ((tileArray [i – 1, j] == 4 ||tileArray [i – 1, j] == 6) &&
          (tileArray [i + 1, j] == 5 ||tileArray [i + 1, j] == 6)) {

                      tileArray [i, j] = 8;
           }
}

 

Leave a comment