Thanks, I really do appreciate it
.
There are a lot of ways to go about the map generation. I'd like to eventually have multiple map generation algorithms, but for now I'm doing something reasonably simple. I'm doing this from memory, but from what I remember, this is the main algorithm:
- Start with a small board (70 x 75 tiles)
- Make every tile water
- Pick a tile at random and make it land.
- Add that tile to a list we'll call tiles to check.
while the number of land tiles is less than some arbitrary number (I think I made mine 35% of the map). . .
- For every tile in the list we made we look at each of their neighboring (i think only water) tiles to determine whether to change them to land or keep it as water.
- The closer this tile is to the first tile that we chose, the greater chance it has of becoming land.
- If we decide to make the tile into land, we add it onto the list of tiles to check.
- Tiles that stay as water don't get added to this list.
Once all neighbors for a particular tile are checked, that center tile gets removed from the list. When the list is empty, you can repeat the process with a new starting tile. Repeat this entire process until we hit a desired number of land tiles.
I then translate this small board onto the larger board, which I described in one of the above posts.
It seems to produce reasonable results, and you have a bit of control over things like the size of a landmass (adjust the weight on distance), the % of the map that is water (adjust the # of desired land tiles), you can dictate certain areas of the map that are more likely to contain water/land (for example, if you want a map with a gigantic ocean in the middle, you can favor starting tiles that are far away from this area), you can control how many continents appear on the map, as well as the size variance between continents (that is, how large the largest continent is in relation to the smallest) by changing the distance weight for each continent you place.
That being said, I'm sure there are better ways to go about it. A lot of people use
perlin noise to generate random maps. I found another project on the web a few weeks ago which generated similar maps in Javascript. You can check out the results, code, and a writeup of that
here if you're interested. I actually highly recommend it, it was really interesting.
For the height, I did something that was roughly this -- All tile corners are at height 0, and there's a list of corners that are locked and will no longer be heightened, and a list of unlocked corners. All corners start out unlocked. First lock all water corners. Iterate over all remaining unlocked corners and randomly either heighten a corner if allowed (i.e. this will not make it too high over any of its neighbors) / do nothing if not allowed, or lock the corner. Keep iterating over the unlocked list until it's empty.