I'm am attempting to add a cave type spawning system to a small game project I am working on.
Here's my code for creating the tile map and filling it with tiles/images.
public static tile[][] map;
public tileMap() {
map = new tile[20][17];
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
if (map[i][j] == null) {
int r = rand(20);
if (r <= grassr) {
map[i][j] = new tile(tiles.grass, i * size, j * size,
true);
} else if (r > grassr && r <= stoner) {
if (rand(20) < 20) {
map[i][j] = new tile(tiles.red, i * size, j * size,
false);
} else {
map[i][j] = new tile(tiles.yellow, i * size, j
* size, false);
w = rand(10);
for (int wi = 0; wi <= w; wi++) {
h = rand(10);
for (int hi = 0; hi <= h; hi++) {
if (i - w >= 1 && j - h >= 1) {
map[i - w][j - h] = new tile(
tiles.yellow, i * size, j
* size, false);
if (h != 0) {
h--;
}
}
}
if (w != 0) {
w--;
}
}
}
}
}
}
}
}
For now I am using the "tiles.yellow" tile for my caves. The issue I am having is that caves seem to be spawning without an image and the yellow tiles seem to be spawning in different places from them.
Does anyone know why the caves are spawning without the image and how I can fix it?
Thanks in advance for any replies!
Aucun commentaire:
Enregistrer un commentaire