Currently I’m working on a project that uses text files to describe tile maps in a level layout. Each text file looks like this:
xxxxxxxx
x x
x x
xxxxxxxx
And each file is sorted into a 2D array of single character strings when the level is initialized.
that’s a simple example, but say I would want to start at a random tile, in this case a ‘x’ or a ’ ', and find all the similar tiles touching it with the flood fill algorithm and add them to a 2D array that corresponds with the tile layout.
I know how a recursive flood fill works, I’m just not sure how to do it while adding them to a 2D array,which is a fixed size and as such makes it impossible to add the strings as I go.
Thanks in advance for any and all help!
This has a flood-fill in an array implemented for pathfinding.
–Eric
do you think it would be applicable in this context? I’m giving it a look now.
To give you an idea of what I’m doing, there are two types of maps, standard maps and super maps. The super maps contain the layout of the entire level where each character represents one standard map, and the standard maps contain each room, where each character corresponds to a tile type. Whenever two or more characters of the same type in the super map are touching each other, their corresponding standard maps are instantiated as a group to create more complex rooms that have more than one map. That’s where the flood fill check algorithm comes in.
Kind of convoluted I know, but the game itself is pretty simple and I didn’t want to write an entire 2D tile editor.
Well, maybe not, but it might give you some ideas.
–Eric