diff options
-rw-r--r-- | kurator/src/Battle.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 74f40f8..d6df0b1 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -56,6 +56,7 @@ Battle::Battle(std::shared_ptr<Session> _session, campaign::Scenario scenario, B registry.emplace<Marker>(entity, 5.0, team_color(team.id), std::move(label)); registry.emplace<PopupEmitter>(entity); } + camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); } @@ -73,7 +74,13 @@ Battle::update(const float dt) { if (IsKeyPressed(KEY_ESCAPE)) return session->set(std::make_shared<Pause>(session, session->current())); - camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); + if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT)) { + const auto delta = GetMouseDelta(); + camera.offset.x -= delta.x / camera.scale; + camera.offset.y -= delta.y / camera.scale; + } + if (IsWindowResized()) + camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); // won't work in frame battle->update(dt * time_factor); auto& registry = battle->registry(); auto timers = registry.view<Timed>(); @@ -127,15 +134,14 @@ Battle::draw() const ClearBackground(BLACK); const int hwidth = GetScreenWidth() / 2; const int hheight = GetScreenHeight() / 2; - const double scale = std::min(hwidth/15000.0, hheight/15000.0); Grid().draw(camera); auto& registry = battle->registry(); auto crosses = registry.view<sim::Transform, Cross>(); for (const auto& [entity, transform, cross] : crosses.each()) { if (cross.timer > cross.phase) continue; - const int x = hwidth + transform.position.x*scale; - const int y = hheight + transform.position.y*scale; + const int x = hwidth + (transform.position.x - camera.offset.x) * camera.scale; + const int y = hheight + (transform.position.y - camera.offset.y) * camera.scale; DrawLine( x - cross.hlength, y - cross.hlength, @@ -157,16 +163,16 @@ Battle::draw() const const auto start = line.start + diff.scale(fstart > 0.0 ? fstart : 0.0); const auto end = line.start + diff.scale(fend > 1.0 ? 1.0 : fend); DrawLine( - hwidth + start.x*scale, - hheight + start.y*scale, - hwidth + end.x*scale, - hheight + end.y*scale, + hwidth + (start.x - camera.offset.x) * camera.scale, + hheight + (start.y - camera.offset.y) * camera.scale, + hwidth + (end.x - camera.offset.x) * camera.scale, + hheight + (end.y - camera.offset.y) * camera.scale, line.color); } auto view = registry.view<const Marker, const sim::Transform>(); for (auto [entity, marker, transform] : view.each()) { - const int x = hwidth + transform.position.x*scale; - const int y = hheight + transform.position.y*scale; + const int x = hwidth + (transform.position.x - camera.offset.x) * camera.scale; + const int y = hheight + (transform.position.y - camera.offset.y) * camera.scale; DrawCircle(x, y, marker.radius, marker.color); DrawLine( x, @@ -178,8 +184,10 @@ Battle::draw() const } auto pops = registry.view<CenteredText, sim::Transform, UIOffset>(); for (const auto& [entity, text, transform, offset] : pops.each()) { - const int x = hwidth + transform.position.x*scale - text.width/2 + offset.x; - const int y = hheight + transform.position.y*scale - text.font_size/2 + offset.y; + const int x = + hwidth + (transform.position.x - camera.offset.x) * camera.scale - text.width/2 + offset.x; + const int y = + hheight + (transform.position.y - camera.offset.y) * camera.scale - text.font_size/2 + offset.y; DrawText(text.text.c_str(), x, y, text.font_size, text.color); } balance.draw(); |