I have been looking into perlin noise for an application I'm working on its basically a '2 dimensional side view' looking game (simulation). I don't fully understand how perlin noise works but get the general idea.
I have found this article with code Perlin Noise and decided to give it ago, the way I have world gen set up at the moment is each 'chunk' has 16x16 tiles and I have just stated that if Y >= HEIGHT / 2 make all tiles 'solid' else 'air' so that's working.. but the land is very flat as you would imagine. Thats where I thought the perlin noise would come in, so I used the code found at the above website, but I am not to sure on how to translate the noise to solid/air tiles.
As you can see not very realistic terrain
Im more looking for the terrain to be like below. should look like mountains and rolling hills) Im not worried about the sharp edges (square)
Im not sure how to iterate through the tile array to turn the noise into above
At the moment I am iterating through the tile array (2d) like so but as you can see from the first picture it just randomizes whether the tile is solid or not, It does not create any rolling hills or mountains.
for(int Y = 0;Y < HEIGHT;++Y) {
for(int X = 0;X < WIDTH;++X) {
Tile Tile;
if(noise(X,Y) < 0) {
Tile.Type = BLOCK;
} else {
Tile.Type = Air;
}
// Then I push the Tile on to a vector
I should also mention that to the right of this 16x16 'chunk' there is another chunk which needs to be match up with this one and same goes with the next chunk after that. Chunks shouldn't be the same as previous just make it look like they are not separate chunks, if that makes sense.
Any help is greatly appreciated! Thank you
UPDATE
I have changed my perlin functions to that of this and I have implemented what phresnel suggested:
PerlinNoise *test=new PerlinNoise(0.25, 6); //0.25 is Persistance 6 is Octaves
float f,h;
float seed = 804.343;
for (int X=0; X!=MAP_WIDTH; ++X) {
f = test->GetNoise((X * ChunkX) * seed);
h = f * MAP_HEIGHT + (MAP_HEIGHT / 2);
for (int y=0; y<h; ++y) {
Tile tempTile;
tempTile.Tile = TILE_NONE;
Tiles[X][y] = tempTile;
}
for (int y=h; y<MAP_HEIGHT; ++y) {
Tile tempTile;
tempTile.TileID = TILE_BLOCK;
Tiles[X][y] = tempTile;
}
}
After doing this it looks a lot better, I X * ChunkX
for each noise as if I didn't every chunk would be the same, so now it looks like the following
As you can see the terrain is more of what I want than before but still doesn't much look like real terrain, as in its not very smooth, is there anything I can do to smooth the overall look of it to create Rolling hills and plains
I removed the creation of tiles under that noise values so its easier to see the range
As you can see it looks OK, the values just need to be 'smoothed' out so they don't look like pseudo-random values. I'm also wondering why the first chunk as seen on the left has the same values right the way through.
Thanks.