So I have a tiled map, that is 98x98 in length.(actually it’s 99x99, but the whole outside border in unwalkable.)
I’m going through with A* pathfinder to find paths,
and I have set in the .tmx map some tiles blocking to 1, and walkable tiles to 0, that way I can use it with A*
So First of all, I just want to make sure my int[][] gets the right values,
public static int[][] mapdata = new int[98][98];
public static void MapInit() throws SlickException {
TiledMap map = new TiledMap("res/testmap.tmx");
int tryingx = 0;
int tryingy = 0;
System.out.println(map.getHeight() + "" + map.getWidth());
for (int x=0;x<((int)map.getWidth() / 32);x++) {
for (int y=0;y<((int)map.getHeight() / 32);y++) {
System.out.println(x + " " + y);
int id = map.getTileId(x, y, 0);
String value = map.getTileProperty(id, "blocked", "true");
if (value.equalsIgnoreCase("true")) {
mapdata[tryingx][tryingy] = 1;
} else {
mapdata[tryingx][tryingy] = 0;
}
}
}
for (int x=0;x<98;x++) {
for (int y=0;y<98;y++) {
System.out.println(mapdata[x][y]);
}
}
A= the row
B= the tile of the row
I actually want to make mapdata[ A ][ B ],
So, per say:
mapdata = {
{1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,1,1,1,1},
{1,0,1,1,1,0,1,1,1,1},
{1,0,1,1,1,0,0,0,1,1},
{1,0,0,0,1,1,1,0,1,1},
{1,1,1,0,1,1,1,0,0,1},
{1,0,1,0,0,0,0,0,1,1},
{1,0,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1}
};
The above code is just an example, but I want my mapdata to be read from the tmx file, not hardcoded like that.
I figured storing all of this data in an array would be easier than a text file, because after that is loaded into the array, I want to be able to set entities to something like “2” for interactable, etc. Is there anyway someone can direct me in the right path so i will be able to load the above mapdata correctly?