Since my other major project has become a nightmare of 30+ database tables, I've decided perhaps it's time to take a break and try some lighter fare. As part of that, I've been experimenting with generating procedural islands in C3 using an array and a simple tilemap. Generating a basic set of islands is relatively easy. The hard part, finding the edges and properly applying a beach. And what's an island without a beach?
Here's link where you can see the current results of testing.
twistedvoid.com/c3examples/Castaway
Here's a link to a 'zoomed' out view that shows the map generation in semi-real time. You'll barely be able to see the buttons so if you don't know what they are, just click and it'll do the rest.
twistedvoid.com/c3examples/Castaway2
Here's a link to a zoomed out view that demonstrates both the unpredictable random array generation used in the previous examples and, the 5 random generators used by the Advanced Random plugin. The difference is amazing.
twistedvoid.com/c3examples/Castaway3
THANK you to everyone who spoon'ed me solutions, ideas and encouragement on this thread:
construct.net/en/forum/construct-3/how-do-i-8/god-need-repeat-until-146195
The journey into the unknown begins.
For those interested, the process for creating these islands is something like this.
- Start with a 200x200 array.
- Fill in Array 3,3 to 197,197 with random numbers.
- Run through the array 3 times, add up the 8 neighboring cells and set that one to the average.
- Total all the cells and get an average of all of them.
- Run through the array and set any cell below the average to the value for the tilemap's water. Anything above the average gets set to the tilemap's square land tile.
- Run through the array and look for small water 'ponds' that create an issue when placing beaches.
- Run through the array and look for 'anomalies' that also create issues when creating beaches until all anomalies are gone.
- Place beaches from one of 12 possible tiles depending on what land and water surrounds it.
- Plant some random tree sprites, change some random terrain sprites to bushes and rocks.
Finding all of the anomalies that prevented beach placement (and identifying arrangements that caused issues) was the hard part. First, it looks to see if a land tile has at least 4 neighboring land tiles.
If it doesn't, it sets it to water. Then, it looks for and fixes issues like this:
where X is land and 0 is water. In both of those cases, there was no way to properly place a beach on the center tile and have it match the surrounding beaches.
Those above were easy to spot. It looks N/S or E/W or diagonally and see if there was a land tile. If not, put one there to smooth it out. The biggest pain in the ass to find and fix was this one which occasionally popped up.
X|X|0|X
X|X|T|X
X|0|X|X
X|0|0|X
It passed by the '4 tile rule' just fine and passed the horizontal and diagonal checks. For that one, I had to create a special rule. For the one labeled T, it checks W and S for land. It then checks SW for water and then, checks N for water. If all those conditions are true, it sets the north tile to land.
So, that's the basics.