diff options
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/game.cpp | 1 | ||||
-rw-r--r-- | src/game/interface.cpp | 20 | ||||
-rw-r--r-- | src/game/units.cpp | 2 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/game/game.cpp b/src/game/game.cpp index fedc403..22b883e 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -74,6 +74,7 @@ void state_t::start(void) soldier->place(&world, v2f_t(1.5, 0.5)); soldier = new unit_soldier_t(this); soldier->place(&world, v2f_t(2.5, 0.5)); + select(rectf_t(v2f_t(0.5, 0.5), v2f_t(2.5, 0.5))); } void state_t::stop(void) diff --git a/src/game/interface.cpp b/src/game/interface.cpp index 67f5482..6512576 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -27,6 +27,20 @@ void state_t::tick(double dt) size = window->getSize(); + if (!game->selected_units.size()) + camera.following = false; + + if (camera.following) { + v2f_t goal(0, 0); + + for (entity_t *ent : game->selected_units) + goal += ent->render_bounds.center(); + goal /= game->selected_units.size(); + + camera.center[0] = expfade(camera.center[0], goal[0], 20, dt); + camera.center[1] = expfade(camera.center[1], goal[1], 20, dt); + } + camera.zoom = expfade(camera.zoom, camera.target_zoom, 15, dt); { @@ -67,6 +81,7 @@ void state_t::tick(double dt) break; case sf::Mouse::Button::Middle: + camera.following = false; camera.panning = true; camera.pan_ref = wmouse; break; @@ -110,6 +125,11 @@ void state_t::tick(double dt) else print(text::get(text::UNPAUSED)); break; + + case sf::Keyboard::Key::F: + camera.following = true; + break; + case sf::Keyboard::Key::F1: debug_draw_cmodels ^= 1; print("debug_draw_cmodels = " + std::to_string(debug_draw_cmodels)); diff --git a/src/game/units.cpp b/src/game/units.cpp index 4e2b2aa..da6b1a3 100644 --- a/src/game/units.cpp +++ b/src/game/units.cpp @@ -431,6 +431,8 @@ void unit_soldier_t::on_think(void) void unit_soldier_t::on_death(void) { + game->selected_units.erase(this); + render_size[0] = v2f_t(-0.75f, -0.5f); render_size[1] = v2f_t(+0.75f, +0.5f); render_layer = -1; |