I've developed a random tile based generator (not a tile map persay), but a random assortment of tiles that generate a path.
It places an image (the tile) at a fixed position in the center of the screen, then chooses a random left/right/up/down choice to place the next tile. From that newest placed tile, it chooses another random left/right/up/down choice and places another tile, etc, etc...
Now, I have found that since the tiles can go in any direction, I don't think I can just create an array and keep track of placements, since I don't know what shape the tiles will make up (no idea how big to make the array). Any options for easy tracking of this (as of right now tiles can overlap)?
Ex) Tile starts at 1, moves to 2, moves to 3, moves to 4, can't move back to 3 or on top of 1 at this point? I'd like to avoid checking all tiles in a loop for locations (as a max number of tiles is constantly changing).
1 - 2
4 - 3
Also, I would like a way to see if I can keep some tiles more block shaped (so it's not just a single path)?
Ex) Sometimes I get stuff like this:
1-2-3
----4-5
------6-7-8-9
When I'd rather have something like this:
1-2-3
--5-4
--6-7-8
----0-9
private void gridjumpergeneratelevel(int tilesmaxwidth, int tilesmaxheight, int tilesmax, int screen)
{
Random randomnumber = new Random();
for(int i=1;i<=tilesmax;i++)
{
int randomnum = randomnumber.Next(1,4);
bool tileplaced
if(i==1) {} //first tile (place at predefined x,y)
else{
do{
//check random number, 1=top,2=left,3=right,4=bottom
//***** Notice, NO Previous Detection Yet ******
switch(rrandomnum){
case 1:
//take previous tile y loc and -120 for new tile
tileplaced=true;
break;
..
}
}while(!tileplaced);
}
}
}
That's essentially a breakdown of the main parts of the function...