summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/assets.cpp8
-rw-r--r--src/game/game.cpp50
-rw-r--r--src/game/game.hpp5
3 files changed, 62 insertions, 1 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index ef7be9b..96199a6 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -24,6 +24,7 @@ spider_assets_t spider;
nest_assets_t nest;
fx_assets_t fx;
deco_assets_t deco;
+ambience_assets_t ambience;
render::animated_texture_t unit_selected;
render::animated_texture_t unit_selected_halo;
@@ -73,6 +74,13 @@ void load(void)
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);
+
+ ambience.nexus.load("assets/ambience/nexus.ogg");
+ ambience.chasm.load("assets/ambience/chasm.ogg");
+ ambience.wind.load("assets/ambience/wind.ogg");
+ ambience.water.load("assets/ambience/water.ogg");
+
+ ambience.nexus.weight = 1.0f;
}
} // namespace game::assets
diff --git a/src/game/game.cpp b/src/game/game.cpp
index 44ea95d..58b2c9d 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -194,7 +194,6 @@ void state_t::resume(void)
paused = false;
}
-
#define TIME_DELTA ((ntime_t)1000000000 / 60)
void state_t::tick(ntime_t time_)
@@ -234,6 +233,55 @@ void state_t::tick(ntime_t time_)
}
}
+void state_t::compute_ambience(render::state_t *render)
+{
+ rectf_t area;
+ size_t plains = 0, cave = 0, water = 0, weird = 0;
+ float scale, volume;
+
+ area = render->window_in_world_space();
+
+ // resolution chosen arbitrarily
+ for (size_t y = 0; y < 5; y++)
+ for (size_t x = 0; x < 5; x++) {
+ v2f_t point;
+ world::tile_t *tile;
+
+ point[0] = lerp(area[0][0], area[1][0], y / 4.0f);
+ point[1] = lerp(area[0][1], area[1][1], x / 4.0f);
+
+ tile = world.get_tile(world::tile_index_t(point), world::SECTOR_FULL);
+
+ switch (tile->type) {
+ case TILE_DIRT:
+ plains++;
+ break;
+
+ case TILE_GRAVEL:
+ case TILE_STONE:
+ cave++;
+ break;
+
+ case TILE_WATER:
+ water++;
+ break;
+
+ case TILE_DIRT_RED:
+ case TILE_STONE_RED:
+ weird++;
+ break;
+ }
+ }
+
+ scale = 1.0f / area.dims().len();
+ volume = clamp(remap(0.002f, 0.08f, 0.0f, 1.0f, scale), 0.0f, 1.0f);
+
+ assets::ambience.wind.weight = plains / 25.0f * volume;
+ assets::ambience.chasm.weight = cave / 25.0f * volume;
+ assets::ambience.water.weight = water / 25.0f * volume;
+ assets::ambience.nexus.weight = weird / 25.0f * volume;
+}
+
die_t::die_t(size_t sides_)
{
sides = sides_;
diff --git a/src/game/game.hpp b/src/game/game.hpp
index 85e3849..8486412 100644
--- a/src/game/game.hpp
+++ b/src/game/game.hpp
@@ -77,11 +77,16 @@ namespace game {
render::animated_texture_t wart;
} deco_assets_t;
+ typedef struct {
+ audio::ambient_t nexus, chasm, wind, water;
+ } ambience_assets_t;
+
extern soldier_assets_t soldier;
extern spider_assets_t spider;
extern nest_assets_t nest;
extern fx_assets_t fx;
extern deco_assets_t deco;
+ extern ambience_assets_t ambience;
extern render::animated_texture_t unit_selected;
extern render::animated_texture_t unit_selected_halo;
extern render::animated_texture_t move_marker;