Okay, so i want to make some game where it randomly generates an island, the noise functions and island masks are all good but i have the following problem: if i want to do this with tiles, i don’t have the tiles for some specific positions
example:
And this is the tiles i have:
I know that I could simply draw the missing tiles, but I would prefer to have the code change the map so that it doesn’t need those tiles.
What i mean is like the following: (Tiles = X and O)
Case 1:
XXX
XOX
XXX
gets changed to
XXX
XXX
XXX
Case 2:
OOXXOO
OOOOOO
OOXXOO
gets changed to
OOXXOO
OOXXOO
OOXXOO
Because these Tiles aren’t supported but I have no idea how this would work for the case in the picture so that i don’t need to draw additional tiles
Code fixing the other 2 Issues and an attempt to count the ones that are still there:
boolean done = false;
int looped = 0;
while (!done) {
Start.errors = 0;
looped++;
done = true;
// REDO
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
// Check null
if (!exist(x - 1, y) || !exist(x + 1, y)
|| !exist(x, y - 1) || !exist(x, y + 1)) {
// Do nothing
} else {
int amount = 0;
type t = null;
if (tiles[(x - 1) + y * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[(x - 1) + y * w];
}
if (tiles[(x + 1) + y * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[(x + 1) + y * w];
}
if (tiles[x + (y - 1) * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[x + (y - 1) * w];
}
if (tiles[x + (y + 1) * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[x + (y + 1) * w];
}
if (amount <= 1) {
// Change
tiles[x + y * w] = t;
done = false;
}
}
}
}
// Lines
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
// Check null
if (!exist(x - 1, y) || !exist(x + 1, y)
|| !exist(x, y - 1) || !exist(x, y + 1)) {
// Do nothing
} else {
int amount = 0;
type t = null;
if (tiles[(x - 1) + y * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[(x - 1) + y * w];
}
if (tiles[(x + 1) + y * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[(x + 1) + y * w];
}
if (tiles[x + (y - 1) * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[x + (y - 1) * w];
}
if (tiles[x + (y + 1) * w] == tiles[x + y * w]) {
amount++;
} else {
t = tiles[x + (y + 1) * w];
}
if (amount == 2) {
if (tiles[x + (y - 1) * w] == tiles[x + (y + 1) * w]) {
if (tiles[x + (y - 1) * w] == tiles[x + y * w]) {
tiles[x + (y - 1) * w] = t;
tiles[x + (y + 1) * w] = t;
} else {
}
tiles[x + y * w] = t;
done = false;
}
}
}
}
}
// Edge to edge
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
// Check null
if (!exist(x - 1, y) || !exist(x + 1, y)
|| !exist(x, y - 1) || !exist(x, y + 1)) {
// Do nothing
} else {
int amount = 0;
if (tiles[(x - 1) + (y - 1) * w] == tiles[x + y * w]) {
amount++;
}
if (tiles[(x + 1) + (y - 1) * w] == tiles[x + y * w]) {
amount++;
}
if (tiles[(x - 1) + (y + 1) * w] == tiles[x + y * w]) {
amount++;
}
if (tiles[(x + 1) + (y + 1) * w] == tiles[x + y * w]) {
amount++;
}
if (amount == 2) {
if (tiles[(x + 1) + (y + 1) * w] == tiles[(x - 1)
+ (y - 1) * w]) {
Start.errors++;
if (done) {
tiles[x + y * w] = type.ERROR;
}
}
}
}
}
}
if (looped >= 10) {
Start.errors = -1;
continue;
}
}