Hey TheChubu !
First thanks for your reply and your praise ^^ Yeah sure :
So first some reading stuff, im using libgdx if that matter. I am using three different layers. First the brick background, than the normal wall layer and an other layer for the different parts of the wall like crossings. For creating the normal wall layer i do that :
for(int y = 0; y < copyOfMap.length; y++){
for(int x = 0; x < copyOfMap[0].length; x++){
if(copyOfMap[y][x] == 1 ||
copyOfMap[y][x] == 4 ||
copyOfMap[y][x] == 10){
if(x < 49 && y < 49 && x > 0 && y > 0){
// 0 = up, 1 = left, 2 = down, 3 = right
boolean[] directions = new boolean[4];
// 0 = right top corner, 1 = right bottom corner, 2 = left top corner, 3 = left bottom corner
boolean[] corners = new boolean[4];
// got an under neighbour
directions[2] = copyOfMap[((int) y)-1][(int) x] == 2 ;
// got an upper neighbour
directions[0] = copyOfMap[((int) y)+1][(int) x] == 2;
// got an left neighbour
directions[1] = copyOfMap[((int) y)][(int) x-1] == 2;
// got an right neighbour
directions[3] = copyOfMap[((int) y)][(int) x+1] == 2;
corners[0] = copyOfMap[y+1][x+1] == 2;
corners[2] = copyOfMap[y+1][x-1] == 2;
corners[3] = copyOfMap[y-1][x-1] == 2;
corners[1] = copyOfMap[y-1][x+1] == 2;
if(directions[3] && !directions[1] && !directions[2] && !directions[0]){
if(!corners[0]){
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 0, 32, 32);
wallLayer.add(region, ((x*100)+100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}
else if(!corners[1]){
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(0, 64, 32, 32);
wallLayer.add(region, ((x*100)+100)/Box2dVars.UNIT, (y*100)/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}
I hope you understand my code, so im looping through the floor tiles. Than im checking for each of them if the floor tile got neighbours which are walls, if yes do the stuff there. There much more if else statements but it would be too long to put them all in here. Because sometimes there problems with my Autotiling system i created a third layer for the problem tiles. This time im looping through the wall tiles and looks if the tile got an floor neighbour. That looks like so ::
for(int y = 0; y < copyOfMap.length;y++){
for(int x = 0; x < copyOfMap[0].length;x++){
switch (copyOfMap[y][x]) {
case 2:
if(y > 0 && x > 0 && y < 49 && x < 49){
// 0 = up, 1 = left, 2 = down, 3 = right
boolean[] directions = new boolean[4];
// 0 = right top corner, 1 = right bottom corner, 2 = left top corner, 3 = left bottom corner
boolean[] corners = new boolean[4];
// got an under neighbour
directions[2] = copyOfMap[((int) y)-1][(int) x] == 2;
// got an upper neighbour
directions[0] = copyOfMap[((int) y)+1][(int) x] == 2;
// got an left neighbour
directions[1] = copyOfMap[((int) y)][(int) x-1] == 2;
// got an right neighbour
directions[3] = copyOfMap[((int) y)][(int) x+1] == 2;
corners[0] = copyOfMap[y+1][x+1] == 2;
corners[2] = copyOfMap[y+1][x-1] == 2;
corners[3] = copyOfMap[y-1][x-1] == 2;
corners[1] = copyOfMap[y-1][x+1] == 2;
if(directions[3] && directions[1] && !directions[0] && directions[2]){
if(!corners[0] && !corners[1] && !corners[2] && !corners[3]){
if(transformGrid[y-1][x] == 10){
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(64, 128, 32, 32);
region.flip(true, false);
wallLayer.add(region, ((x*100))/Box2dVars.UNIT, ((y*100))/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}
else{
region = game.manager.get("DuengonGainersAtlas/DuengonGainersAtlas",TextureAtlas.class).findRegion("Duengon-WallSet");
region.setRegion(64, 128, 32, 32);
region.flip(false, false);
wallLayer.add(region, ((x*100))/Box2dVars.UNIT, ((y*100))/Box2dVars.UNIT,100/Box2dVars.UNIT,100/Box2dVars.UNIT);
}
}
Normally there again much more if else statements, isnt there a easier way to implement autotiling into a game ? And am i doing autotiling right or are there some mistakes ? What could i do better ? :)
Thanks for your time and your help ! :D