diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-10-21 14:46:35 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-10-21 14:46:35 +0200 |
commit | ee017fb5def1c4d372a664e5e64210ed0cd52174 (patch) | |
tree | e3c39a8a049b2a1c254ec13d6996c1bdb8bceaff | |
parent | f08fb7293382dbaf240860119d128486ada62221 (diff) |
Slightly more interesting world generation.
-rw-r--r-- | src/render.cpp | 3 | ||||
-rw-r--r-- | src/world.cpp | 15 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/render.cpp b/src/render.cpp index 87f4216..907dcf0 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -28,6 +28,9 @@ static void draw_tile(sf::RenderWindow *window, v2f_t x, world::tile_t *tile) case 3: color = sf::Color(29, 190, 45); break; + case 4: + color = sf::Color(120, 120, 120); + break; default: ; } diff --git a/src/world.cpp b/src/world.cpp index 895eb0f..ad055c0 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -26,9 +26,11 @@ void world_t::generate_tile(tile_t *tile, tile_index_t x) waterlevel = perlin.get(x, 1000.0f) * 0.3f + perlin.get(x, 500.0f) * 0.1f; - height = perlin.get(x, 10.0f) * 0.6f + - perlin.get(x, 5.0f) * 0.25f + - perlin.get(x, 3.0f) * 0.2f; + 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 - 0.2f) tile->type = -1; @@ -41,6 +43,10 @@ void world_t::generate_tile(tile_t *tile, tile_index_t x) tile->type = 3; else tile->type = 2; + + if (height > waterlevel + 0.1f && + perlin.get(x, 2.0f) > 0.3f) + tile->type = 4; } } @@ -75,7 +81,8 @@ bool world_t::find_path(v2f_t src, v2f_t dst, rectf_t size, tile_index_t index; index = finder.base + tile_index_t(x, y); - node->accessible = (get_tile(index)->type >= 1); + node->accessible = (get_tile(index)->type >= 1 && + get_tile(index)->type <= 3); } if (!finder.find()) |