I have a “grid” setup for a 2d game I’m making, and I would like to create the map almost like a forkbomb:
Say there’s a tile, and 1-3 of positions left, top, right, and/or bottom instantiate a new floor tile, and from each tile, it continues this same idea from the new set of positions. ex: first places tile left and top of 1st tile, left instantiates tile bottom and left, and right of 1st instantiates a tile top.
I know how to do once from a tile, but not continue it automatically with constantly varying x/y coordinates.
Thanks!
My code:
void rooms () {
taken [1,1] = true;
tilePlace ();
foreach (int nW in mapW) { //instantiate floor at all taken
foreach (int nH in mapH) {
if (taken [nW, nH] == true) {
Instantiate (mapTile, new Vector2 (nW - (0.2f * nW), nH - (0.2f * nH)), Quaternion.identity);
}
}
}
foreach (int nW in mapW) { //instantiate wall at all not taken
foreach (int nH in mapH) {
if (taken [nW, nH] == false) {
Instantiate (wall, new Vector2 (nW - (0.2f * nW), nH - (0.2f * nH)), Quaternion.identity);
}
}
}
}
void tilePlace(){
int placements = Random.Range (1, 4); // # of placements around tile
for (int i = 0; i < placements; i++) {
int place = Random.Range (1, 4); // random place to instantiate
if (place == 1) {
taken [1,2] = true; // 1,2 are coordinates to place
}
if (place == 2) {
taken [2,1] = true;
}
if (place == 3) {
taken [1,0] = true;
}
if (place == 4) {
taken [0,1] = true;
}
}
}