diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/assets.cpp | 4 | ||||
-rw-r--r-- | src/game/game.cpp | 5 | ||||
-rw-r--r-- | src/game/game.hpp | 7 | ||||
-rw-r--r-- | src/game/interface.cpp | 22 | ||||
-rw-r--r-- | src/game/unit_repl.cpp | 16 | ||||
-rw-r--r-- | src/game/unit_scientist.cpp | 6 | ||||
-rw-r--r-- | src/game/worldgen.cpp | 4 |
7 files changed, 55 insertions, 9 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp index 96666a3..aedad52 100644 --- a/src/game/assets.cpp +++ b/src/game/assets.cpp @@ -28,10 +28,10 @@ repl_assets_t repl; fx_assets_t fx; deco_assets_t deco; audio::ambient_t ambients[AMBIENT_COUNT]; - render::animated_texture_t unit_selected; render::animated_texture_t unit_selected_halo; render::animated_texture_t move_marker, aim_marker; +ui_assets_t ui; void load(void) { @@ -148,6 +148,8 @@ void load(void) ambients[AMBIENT_WIND].volume = 3.0f; ambients[AMBIENT_WATER].load("assets/ambience/water.ogg"); ambients[AMBIENT_WATER].volume = 0.1f; + + ui.crystals.load("assets/ui/crystals_", 1); } } // namespace game::assets diff --git a/src/game/game.cpp b/src/game/game.cpp index 086b926..30e4fba 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -78,16 +78,13 @@ void entity_t::sleep(void) void state_t::start(void) { - unit_soldier_t *soldier; unit_repl_t *repl; world.generator = worldgen; world.generator_data = (void*)this; - soldier = new unit_soldier_t(this); - soldier->place(&world, v2f_t(0.5, 0.5)); repl = new unit_repl_t(this); - repl->place(&world, v2f_t(1.5, 0.5)); + repl->place(&world, v2f_t(1.3, -0.6)); resume(); } diff --git a/src/game/game.hpp b/src/game/game.hpp index e48e2a3..b9b593e 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -146,6 +146,8 @@ namespace game { void select(rectf_t rect, int type); bool populate_pie_menu(std::vector<interface::pie_item_t> &items); void command(v2f_t x, int number); + + size_t crystals = 150; }; enum { @@ -246,6 +248,10 @@ namespace game { render::animated_texture_t crystal, crystal_broken; } deco_assets_t; + typedef struct { + render::animated_texture_t crystals; + } ui_assets_t; + extern soldier_assets_t soldier; extern scientist_assets_t scientist; extern builder_assets_t builder; @@ -258,6 +264,7 @@ namespace game { extern render::animated_texture_t unit_selected; extern render::animated_texture_t unit_selected_halo; extern render::animated_texture_t move_marker, aim_marker; + extern ui_assets_t ui; void load(void); } diff --git a/src/game/interface.cpp b/src/game/interface.cpp index 5b89f58..9e43839 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -406,6 +406,7 @@ static void render_avatar(render::state_t *render, game::unit_t *unit, v2f_t at, void state_t::render_to(render::state_t *render) { size_t w = window->getSize().x, h = window->getSize().y; + rectf_t rect; v2f_t x; std::stringstream ss; v2f_t avatar_size; @@ -468,14 +469,31 @@ void state_t::render_to(render::state_t *render) i++; } - x = v2f_t(0.0f, 0.0f); + rect = rectf_t(v2f_t(0.0f, 0.0f), v2f_t(w, 1.1f * em)); + render->render_rect(rect, sf::Color(0, 0, 0, 140)); + + rect = rectf_t(v2f_t(0.0f, 0.0f), 1.1f * v2f_t(em, em)); + render->render(0.0, &assets::ui.crystals, rect, sf::Color::White); + + x = v2f_t(1.1f * em, 0.0f); + render->render_text(x, em, std::to_string(game->crystals), render::ALIGN_LEFT_TOP, sf::Color::White); + + x = v2f_t(w - 0.3f * em, 0.0f); + if (game->paused) + ss << "PAUSED "; + ss << game->time / SEC(60); + ss << ":"; + ss << std::setw(2) << std::setfill('0') << game->time / SEC(1) % 60 << std::setw(0); + render->render_text(x, em, ss.str(), render::ALIGN_RIGHT_TOP, sf::Color::White); + + x = v2f_t(0.0f, rect[1][1]); for (log_entry_t &entry : log) { render->render_text(x, em, entry.text, render::ALIGN_LEFT_TOP, sf::Color::White); x[1] += em; } x = v2f_t(0.0f, h - em * 1.5); - + ss.str(std::string()); ss << std::fixed << std::setprecision(3); ss << "Game t/F/B: " << game->time * 1.0e-9 << "/" << game->frames << "/" << game->frames_behind; render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White); diff --git a/src/game/unit_repl.cpp b/src/game/unit_repl.cpp index 6dfa005..ddea8b0 100644 --- a/src/game/unit_repl.cpp +++ b/src/game/unit_repl.cpp @@ -54,10 +54,26 @@ void unit_repl_t::render_to(render::state_t *render) void unit_repl_t::activate(unit_t::type_t type) { + size_t price; world::cmodel_t cmodel; unit_t *unit; switch (type) { + case UNIT_SOLDIER: price = 40; break; + case UNIT_SCIENTIST: price = 95; break; + case UNIT_BUILDER: price = 70; break; + default: + abort(); + } + + if (game->crystals < price) { + game->interface.print("Insufficient crystals; " + std::to_string(price - game->crystals) + " more needed."); + return; + } + + game->crystals -= price; + + switch (type) { case UNIT_SOLDIER: unit = new unit_soldier_t(game); break; diff --git a/src/game/unit_scientist.cpp b/src/game/unit_scientist.cpp index bac2a23..129d7fa 100644 --- a/src/game/unit_scientist.cpp +++ b/src/game/unit_scientist.cpp @@ -57,6 +57,7 @@ void unit_scientist_t::gather_crystals(void) world::trace_t trace; bool found = true; deco_t *deco; + size_t crystals; if (!move.moving) start_moving(gathering_at); @@ -76,6 +77,11 @@ void unit_scientist_t::gather_crystals(void) goto out; } + crystals = game->prng.next() % 100 + 1; + game->crystals += crystals; + game->interface.print(name + " collected " + std::to_string(crystals) + " " + + (crystals == 1 ? "crystal" : "crystals")); + deco->type = DECO_CRYSTAL_BROKEN; assets::scientist.gather.play_3d(x); diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp index 9d6ccd3..7af6315 100644 --- a/src/game/worldgen.cpp +++ b/src/game/worldgen.cpp @@ -78,9 +78,9 @@ just_decos: break; case TILE_DIRT: - if (noise > 0.37) + if (noise > 0.35) type = DECO_CRYSTAL; - else if (noise > 0.36) + else if (noise > 0.34) type = DECO_CRYSTAL_BROKEN; else if (noise > 0.33) type = DECO_STONE; |