summaryrefslogtreecommitdiff
path: root/src/game/worldgen.cpp
blob: 573d03baa7c44681d8f8c014bc56d12f719d4928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "game.hpp"

namespace game {

void worldgen(world::tile_t *tile, world::tile_index_t x,
              procgen::perlin_noise_t *perlin)
{
	float waterlevel, height;

	waterlevel = perlin->get(x, 1000.0f) * 0.3f +
	             perlin->get(x, 500.0f) * 0.1f;

	height = perlin->get(x, 40.0f) * 0.6f +
	         perlin->get(x, 20.0f) * 0.25f +
	         perlin->get(x, 10.0f) * 0.2f +
	         perlin->get(x, 4.0f) * 0.1f +
	         perlin->get(x, 1.0f) * 0.05f;

	if (height < waterlevel)
		tile->type = TILE_WALL;
	else if (height < waterlevel + 0.1)
		tile->type = TILE_DIRT;
	else if (perlin->get(x, 3.0f) > 0.0f)
		tile->type = TILE_WALL;
	else
		tile->type = TILE_DIRT;
}

}