Search code examples
javatile

World Tile Generator


I have a game, and recently decided to switch from TilED (a tile map editor), to doing it manually. I've been searching all over google for some help, but to no avail. Here's my code that renders my background using sky tiles:

for (int x = 0; x < 16; x++) {
           for (int y = 0; y < 16; y++) {
              map[x][y] = AIR; 
              if(map[x][y] == AIR) {
                 air.draw(x * tilesize, y * tilesize);
              }

           }
        }

This just creates a new 16 * 16 map and fills it with sky tiles. My question is, how do I specify levels for other tiles to go? So like grass tiles go on layer 10, dirt goes through 9 - 6, and stone fills the rest?


Solution

  • To do it on each level you would just do another for loop:

    for(int x = 0; x < 16; x++) {
        map[x][10] = GRASS;
    }
    

    And that is how you would make it work. Hope it helps!