diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/assets.cpp | 4 | ||||
-rw-r--r-- | src/game/decos.cpp | 56 | ||||
-rw-r--r-- | src/game/game.cpp | 1 | ||||
-rw-r--r-- | src/game/game.hpp | 27 | ||||
-rw-r--r-- | src/game/worldgen.cpp | 78 |
5 files changed, 143 insertions, 23 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp index 2f913ba..a908962 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -5,6 +5,7 @@ namespace game::assets { human_assets_t human; alien_assets_t alien; fx_assets_t fx; +deco_assets_t deco; void load(void) { @@ -22,6 +23,9 @@ void load(void) fx.blood.load("assets/units/blood_", 4); + deco.stone.load("assets/deco/stone_", 1); + deco.eyething.load("assets/deco/eyething_", 2); + world::register_tile(TILE_DIRT, 0); render::register_tile(TILE_DIRT, "assets/tiles/dirt.png"); world::register_tile(TILE_STONE, CF_SOLID); diff --git a/src/game/decos.cpp b/src/game/decos.cpp new file mode 100644 index 0000000..2307762 --- /dev/null +++ b/src/game/decos.cpp @@ -0,0 +1,56 @@ +#include "game.hpp" + +namespace game { + +static const struct { + render::animated_texture_t *texture; + v2f_t mins, maxs; + world::cflags_t cflags; + v2f_t render_mins, render_maxs; + double fps; +} decos[ ] = { + { + &assets::deco.stone, + {-0.4f, +0.1f}, {+0.4f, +0.4f}, CF_SOLID, + {-0.4f, -0.4f}, {+0.4f, +0.4f}, 0.0 + }, + { + &assets::deco.stone, + {-0.2f, +0.1f}, {+0.2f, +0.2f}, CF_SOLID, + {-0.2f, -0.2f}, {+0.2f, +0.2f}, 0.0 + }, + { + &assets::deco.eyething, + {-0.4f, +0.1f}, {+0.4f, +0.4f}, CF_SOLID, + {-0.4f, -1.2f}, {+0.4f, +0.4f}, 0.3 + } +}; + +deco_t::deco_t(game::state_t *game_, deco_type_t type_) : entity_t(ET_DECO) +{ + game = game_; + type = type_; +} + +void deco_t::spawn(world::world_t *world, v2f_t x) +{ + v2f_t center, offset; + + 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; + + cmodel.bounds[0] = center + decos[type].mins; + cmodel.bounds[1] = center + decos[type].maxs; + cmodel.cflags = decos[type].cflags; + render_bounds[0] = center + decos[type].render_mins; + render_bounds[1] = center + decos[type].render_maxs; + link(world); +} +void deco_t::render_to(render::state_t *render) +{ + render->render(game->now * decos[type].fps + phase_shift, + decos[type].texture, render_bounds, sf::Color::White); +} + +} // namespace game diff --git a/src/game/game.cpp b/src/game/game.cpp index 3005bd5..993f450 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -10,6 +10,7 @@ void state_t::start(void) alien_t *alien; world.generator = worldgen; + world.generator_data = (void*)this; human = new human_t(this); human->place(&world, v2f_t(0.5, 0.5)); diff --git a/src/game/game.hpp b/src/game/game.hpp index 58892ff..e1eca84 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -3,7 +3,8 @@ namespace game { enum { ET_UNIT, - ET_EFFECT + ET_EFFECT, + ET_DECO }; enum { @@ -23,8 +24,7 @@ namespace game { extern size_t selection_cookie; - void worldgen(world::tile_t *tile, world::tile_index_t x, - procgen::perlin_noise_t *perlin); + void worldgen(world::world_t *world, world::sector_index_t index, world::sector_t *sector, void *data); namespace assets { typedef struct { @@ -43,9 +43,14 @@ namespace game { render::animated_texture_t blood; } fx_assets_t; + typedef struct { + render::animated_texture_t stone, eyething; + } deco_assets_t; + extern human_assets_t human; extern alien_assets_t alien; extern fx_assets_t fx; + extern deco_assets_t deco; void load(void); } @@ -176,4 +181,20 @@ namespace game { ~fx_blood_t(void) = default; void render_to(render::state_t *render); }; + + typedef enum { + DECO_STONE, + DECO_STONE_SMALL, + DECO_EYETHING + } deco_type_t; + + class deco_t : public world::entity_t { + game::state_t *game; + deco_type_t type; + public: + double phase_shift; + deco_t(game::state_t *game, deco_type_t type_); + void spawn(world::world_t *world, v2f_t x); + void render_to(render::state_t *render); + }; }; diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp index 62c8a5e..74a07c7 100644 --- a/src/game/worldgen.cpp +++ b/src/game/worldgen.cpp @@ -2,28 +2,66 @@ namespace game { -void worldgen(world::tile_t *tile, world::tile_index_t x, - procgen::perlin_noise_t *perlin) +using namespace world; + +void add_decoration(world_t *world, state_t *game, v2f_t x, float noise) { - 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_WATER; - else if (height < waterlevel + 0.1) - tile->type = TILE_DIRT; - else if (perlin->get(x, 3.0f) > 0.0f) - tile->type = TILE_STONE; + deco_t *deco; + deco_type_t type; + + if (noise < 0.3) + return; + + if (noise > 0.45) + type = DECO_EYETHING; + else if (noise > 0.35) + type = DECO_STONE; else - tile->type = TILE_DIRT; + type = DECO_STONE_SMALL; + + deco = new deco_t(game, type); + deco->spawn(world, x); + deco->phase_shift = noise * 500.0; +} + +void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data) +{ + state_t *game = (game::state_t*)data; + + for (coord_t ly = 0; ly < SECTOR_SIZE; ly++) + for (coord_t lx = 0; lx < SECTOR_SIZE; lx++) { + tile_t *tile = sector->tiles + ly * SECTOR_SIZE + lx; + tile_index_t tile_index(index[0] * SECTOR_SIZE + lx, + index[1] * SECTOR_SIZE + ly); + v2f_t x; + float waterlevel, height; + float deco_noise; + + 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; + + 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; + + deco_noise = world->perlin.get(x, 0.125559f); + + if (tile->type == TILE_DIRT) + add_decoration(world, game, x, deco_noise); + } } } |