I'm trying to make a map generator for a 2d tilemap game (similar to games like Civilization - I'd like the ability to create small islands, or large continents, etc). I found an article that does pretty much what I'd like, but it's written in flash. Looks like there's a convenient function to generate a bitmap from perlin noise:
class BitmapData
function perlinNoise(
baseX:Number,
baseY:Number,
numOctaves:uint,
randomSeed:int,
stitch:Boolean,
fractalNoise:Boolean,
channelOptions:uint = 7,
grayScale:Boolean = false,
offsets:Array = null):
This is being used in the article (but I'm using java). So now I'm stuck at trying to implement perlin noise myself (basically finding a pure java implementation and copy/pasting it).
I'm just trying to understand the basic principle behind using perlin noise - my basic understanding:
- Define the size of map you want (in my case about 100 x 50 tiles).
- Initialize a perlin noise object (setting params like frequency etc - not quite sure how these params affect things like island size etc, but putting aside for the moment).
- Iterate over each tile in my map, and ask the perlin noise object for a value. The returned value can be interpreted as a height value I'm guessing.
- Now assign a tile type based on the height value.
The iteration code might look something like:
for (int x = 0; x < 100; x++) {
for (int y = 0; y < 50; y++) {
int height = perlin.getValue(x, y);
if (height < 5); // this tile is water
else if (height < 20); // this tile is shore
else if (height < 40); // this tile is hill
else // this tile is mountain
}
}
Is that generally correct? That would at least be a starting point.
The article (written in flash) that does what I'm looking for: http://www.nolithius.com/game-development/world-generation-breakdown
Flash BitmapData class which conveniently has a perlin noise function built in: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#perlinNoise()
Thanks