diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-19 20:59:06 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-19 20:59:06 +0100 |
commit | 1e702f4e99858d297607a7c1fde7d2df661ae324 (patch) | |
tree | 3d6781d0c37964c1660772d359127eddcbb7fb7e /src/game | |
parent | fab23ff0b70f338fcaeadf11d3855e705e0be6be (diff) |
More biomes and decos.
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/assets.cpp | 9 | ||||
-rw-r--r-- | src/game/decos.cpp | 5 | ||||
-rw-r--r-- | src/game/game.hpp | 9 | ||||
-rw-r--r-- | src/game/worldgen.cpp | 119 |
4 files changed, 110 insertions, 32 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp index 66d3bc8..241e3d7 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -34,17 +34,24 @@ void load(void) deco.stone.load("assets/deco/stone_", 1); deco.eyething.load("assets/deco/eyething_", 2); deco.spike.load("assets/deco/spike_", 1); - deco.spike_small.load("assets/deco/spike_small_", 1); + deco.spike_small.load("assets/deco/spike_small_", 1); + deco.wart.load("assets/deco/wart_", 1); unit_selected.load("assets/units/selected_", 1); unit_selected_halo.load("assets/units/selected_halo_", 1); world::register_tile(TILE_DIRT, 0); render::register_tile(TILE_DIRT, "assets/tiles/dirt.png", NULL, 0.0f); + world::register_tile(TILE_DIRT_RED, 0); + render::register_tile(TILE_DIRT_RED, "assets/tiles/dirt_red.png", NULL, 0.0f); world::register_tile(TILE_STONE, CF_SOLID); render::register_tile(TILE_STONE, "assets/tiles/stone.png", "assets/tiles/stone_side.png", 1.0f); + world::register_tile(TILE_STONE_RED, CF_SOLID); + render::register_tile(TILE_STONE_RED, "assets/tiles/stone_red.png", "assets/tiles/stone_red_side.png", 1.4f); world::register_tile(TILE_WATER, CF_WATER); render::register_tile(TILE_WATER, "assets/tiles/water.png", NULL, 0.0f); + world::register_tile(TILE_GRAVEL, 0); + render::register_tile(TILE_GRAVEL, "assets/tiles/gravel.png", NULL, 0.0f); } } // namespace game::assets diff --git a/src/game/decos.cpp b/src/game/decos.cpp index ff7cb31..4b92c8e 100644 --- a/src/game/decos.cpp +++ b/src/game/decos.cpp @@ -33,6 +33,11 @@ static const struct { &assets::deco.spike_small, {-0.2f, +0.1f}, {+0.2f, +0.2f}, 0, {-0.2f, -0.6f}, {+0.2f, +0.2f}, 0.0 + }, + { + &assets::deco.wart, + {-0.2f, +0.1f}, {+0.2f, +0.2f}, 0, + {-0.2f, -0.2f}, {+0.2f, +0.2f}, 0.0 } }; diff --git a/src/game/game.hpp b/src/game/game.hpp index 7adc307..e609992 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -10,8 +10,11 @@ namespace game { enum { TILE_NONE, TILE_DIRT, + TILE_DIRT_RED, TILE_STONE, - TILE_WATER + TILE_STONE_RED, + TILE_WATER, + TILE_GRAVEL }; enum { @@ -52,6 +55,7 @@ namespace game { typedef struct { render::animated_texture_t stone, eyething; render::animated_texture_t spike, spike_small; + render::animated_texture_t wart; } deco_assets_t; extern soldier_assets_t soldier; @@ -285,7 +289,8 @@ namespace game { DECO_STONE_SMALL, DECO_EYETHING, DECO_SPIKE, - DECO_SPIKE_SMALL + DECO_SPIKE_SMALL, + DECO_WART } deco_type_t; class deco_t : public game::entity_t { diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp index f7d4757..8a6addf 100644 --- a/src/game/worldgen.cpp +++ b/src/game/worldgen.cpp @@ -4,9 +4,9 @@ namespace game { using namespace world; -static void add_entity(world_t *world, state_t *game, v2f_t x) +static void add_entity(uint8_t tile_type, world_t *world, state_t *game, v2f_t x) { - float noise; + float noise, noise_nest, noise_spider; deco_t *deco; deco_type_t type; v2f_t center, offset; @@ -14,33 +14,77 @@ static void add_entity(world_t *world, state_t *game, v2f_t x) noise = world->perlin.get(x, 0.53213f) + world->perlin.get(x, 0.12994f); noise = fabs(noise / 2); - if (noise < 0.16) - return; - offset[0] = world->perlin.get(x, 0.17331f); offset[1] = world->perlin.get(x, 0.19571f); center = x + v2f_t(0.5f, 0.5f) + offset.norm() * 0.1; - if (noise > 0.42) { + switch (tile_type) { + case TILE_DIRT: + noise_nest = 0.42f; + noise_spider = 0.39f; + break; + + case TILE_DIRT_RED: + noise_nest = 0.45f; + noise_spider = 0.41f; + break; + + case TILE_GRAVEL: + noise_nest = 0.36f; + noise_spider = 0.33f; + break; + + default: + goto just_decos; + } + + + if (noise > noise_nest) { unit_nest_t *nest = new unit_nest_t(game); nest->place(world, center); return; - } else if (noise > 0.39) { + } else if (noise > noise_spider) { unit_spider_t *spider = new unit_spider_t(game); spider->place(world, center); return; } - if (noise > 0.36) - type = DECO_EYETHING; - else if (noise > 0.33) - type = DECO_STONE; - else if (noise > 0.26) - type = DECO_SPIKE; - else if (noise > 0.20) - type = DECO_SPIKE_SMALL; - else - type = DECO_STONE_SMALL; +just_decos: + switch (tile_type) { + case TILE_DIRT_RED: + if (noise > 0.21) + type = DECO_EYETHING; + else if (noise > 0.08) + type = DECO_WART; + else + return; + break; + + case TILE_DIRT: + if (noise > 0.33) + type = DECO_STONE; + else if (noise > 0.26) + type = DECO_SPIKE; + else if (noise > 0.20) + type = DECO_SPIKE_SMALL; + else if (noise > 0.16) + type = DECO_STONE_SMALL; + else + return; + break; + + case TILE_GRAVEL: + if (noise > 0.30) + type = DECO_STONE; + else if (noise > 0.13) + type = DECO_STONE_SMALL; + else + return; + break; + + default: + return; + } deco = new deco_t(game, type); deco->phase_shift = offset[0] * 500.0; @@ -61,27 +105,46 @@ void worldgen(world_t *world, sector_index_t index, sector_t *sector, tile_index_t tile_index(index[0] * SECTOR_SIZE + lx, index[1] * SECTOR_SIZE + ly); v2f_t x; - float waterlevel, height; + float biome, waterlevel, height; x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly); waterlevel = world->perlin.get(x, 1000.0f) * 0.3f + world->perlin.get(x, 500.0f) * 0.1f; + biome = world->perlin.get(x - v2f_t(60, 20), 160.0f) * 0.4f + + world->perlin.get(x, 30.0f) * 0.2f + + world->perlin.get(x, 5.0f) * 0.03f; + + height = world->perlin.get(x, 40.0f) * 0.6f + world->perlin.get(x, 20.0f) * 0.25f + world->perlin.get(x, 10.0f) * 0.2f + world->perlin.get(x, 4.0f) * 0.1f + world->perlin.get(x, 1.0f) * 0.05f; - if (height < waterlevel) - tile->type = TILE_WATER; - else if (height < waterlevel + 0.1) - tile->type = TILE_DIRT; - else if (world->perlin.get(x, 3.0f) > 0.0f) - tile->type = TILE_STONE; - else - tile->type = TILE_DIRT; + if (biome < 0.0f) { + if (height < waterlevel) + tile->type = TILE_WATER; + else if (height < waterlevel + 0.1) + tile->type = TILE_DIRT; + else if (world->perlin.get(x, 3.0f) > 0.0f) + tile->type = TILE_STONE; + else + tile->type = TILE_DIRT; + } else if (biome < 0.1f) { + if (height < waterlevel - 0.07f) + tile->type = TILE_STONE; + else + tile->type = TILE_GRAVEL; + } else { + if (height < waterlevel) + tile->type = TILE_DIRT_RED; + else if (world->perlin.get(x, 3.0f) > 0.0f) + tile->type = TILE_STONE_RED; + else + tile->type = TILE_DIRT_RED; + } } decos: @@ -96,9 +159,7 @@ decos: v2f_t x; x = v2f_t(index) * SECTOR_SIZE + v2f_t(lx, ly); - - if (tile->type == TILE_DIRT) - add_entity(world, game, x); + add_entity(tile->type, world, game, x); } } |