I've implemented a cellular automata algorithm to generate a cave for my game and now I need my player object, which occupies 3x3 tiles in total, to be able to pass between the rooms.
The problem is that some of the rooms automatically created by cellular automata do not have the necessary width/height for the object to pass (example: a 2 x 3 tiles corridor).
How can I transform the result from the cellular automata so that I guarantee that the player is able to pass in any of the rooms? The idea is that this can be done in real time so that I can do an endless game.
This was done in GDScript but any examples in any other language, like C# for Unity, are welcome.
As said in the comments, I could make a map where each cell would correspond to a 3x3 on the final map but, my problem is that I need the 1x1 tiles because my player should lose a life when hitting the walls (and that way I can create some kind of "spikes" based on the walls).
Given that, how can I add 1x1 tiles to the map created from the 3x3 and still guarantee that the player fits the cave's "corridors"?
The only rules I currently have for CA are:
- If total neighbour walls > 4, the cell becomes a wall
- If total neighbour walls < 4, the cell becomes empty
- Else, remains as it is
The total number of iterations for the CA is 2
I was able to do this the way that DMGregory said:
- First I run the CA after building the map as I did before in order to add the "empty space adjacent to wall" cells (now on called EmptyNextToWall) to the map
- Then I run the CA with the following rules, until none of them are verified (it did not pass 5 iterations on my scenarios):
- If my current cell is EmptyNextToWall and has more than 4 EmptyNextToWall adjacent to it, make it an Empty cell
- If my current cell is EmptyNextToWall and the adjacent diagonals are a Wall and a EmptyNextToWall, make it an Empty cell
- If my current cell is EmptyNextToWall and there's no Empty cells around it, make it an Empty cell
- If my current cell is a Wall and there's at least one adjacent Empty cell, make it an EmptyNextToWall
- If my current cell is EmptyNextToWall and there's no adjacent Walls, make it an Empty cell