I'm not a completly beginner to java, so I decided to write a map loader and a tileset loader myself instead of using a tilemap editor like Tiled. I'm using Slick & LWJGL for my game.
The plan was to load every map and tileset from external files. When creating a new map, you'd be able to assign tilesets to your map which define the tiles used to paint the map.
I've already written a tileset loader which creates tiles from an external file. For example:
0|floor|tiles/floor.png;
is a tile where id=0, floor means the player in the game would be able to walk on that tile, tiles/floor.png is the texture of the tile.
The tiles are stored in an array in the tileset class.
But I don't know how to create the map loader. Example for a map:
1, 1, 1, 1, 1;
1, 0, 0, 0, 1;
1, 0, 2, 0, 1;
etc. The numbers symbolize the id's of the tiles.
Is there any way to realize my plans? Or is there a better way?
Thanks in advance.
PS: Sorry for my english, I'm no native speaker.
My current solution:
public void createTiles() {
for(int y = 0; y < map.length; y++) {
for(int x = 0; x < map[y].length; x++) {
for(int i = 0; i < tileSets.length; i++) {
for(int j = 0; j < tileSets[i].tiles.length; j++) {
if(map[y][x] == j) {
Tile tile = new Tile(tileSets[i].tiles[j].texture, x, y, xOff, yOff, tileSets[i].tiles[j].isWall);
tileList.add(tile);
}
}
}
}
}
}