diff options
author | Aki <please@ignore.pl> | 2023-02-10 23:21:21 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-02-10 23:21:21 +0100 |
commit | b6f4678d6466e2b16f32d4fd350b10af5720dd11 (patch) | |
tree | 3900e1ab37f70bd25cd2b96c15df5fd9645d4058 | |
parent | 4487c71fc69af45a9c0786248b6a2af0b35cf86a (diff) | |
download | kurator-b6f4678d6466e2b16f32d4fd350b10af5720dd11.zip kurator-b6f4678d6466e2b16f32d4fd350b10af5720dd11.tar.gz kurator-b6f4678d6466e2b16f32d4fd350b10af5720dd11.tar.bz2 |
Extracted Battle systems to own functions
-rw-r--r-- | kurator/src/Battle.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 0f1f0ba..7a34841 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -83,6 +83,12 @@ time_controls(const char* id, float& time_factor) } +static void progress_timers(entt::registry& registry, float dt, float time_factor); +static void move_ui_pops(entt::registry& registry, float dt); +static void blink_crosses(entt::registry& registry, float dt); +static void animate_lines(entt::registry& registry, float dt, float time_factor); + + void Battle::update(const float dt) { @@ -97,12 +103,34 @@ Battle::update(const float dt) camera.scale = std::min(GetScreenWidth()/30000.0, GetScreenHeight()/30000.0); // won't work in frame battle->update(dt * time_factor); auto& registry = battle->registry(); + progress_timers(registry, dt, time_factor); // clock? + move_ui_pops(registry, dt); + blink_crosses(registry, dt); + animate_lines(registry, dt, time_factor); + balance.update(registry); + ImGui::SetNextWindowPos({GetScreenWidth()/2.0f, GetScreenHeight()-100.0f}, ImGuiCond_Once, {0.5f, 0.5f}); + ImGui::SetNextWindowSize({240.0f, 0.0f}, ImGuiCond_Once); + if (ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_NoFocusOnAppearing)) + time_controls("TimeControls", time_factor); + ImGui::End(); +} + + +void +progress_timers(entt::registry& registry, const float dt, const float time_factor) +{ auto timers = registry.view<Timed>(); for (auto&& [entity, timer] : timers.each()) { timer.left -= timer.scaled ? dt * time_factor : dt; if (timer.left < 0.0) registry.destroy(entity); } +} + + +void +move_ui_pops(entt::registry& registry, const float dt) +{ auto pops = registry.view<PopMove, UIOffset>(); for (auto&& [entity, pop, offset] : pops.each()) { const auto speed = pop.speed.scale(dt); @@ -112,6 +140,12 @@ Battle::update(const float dt) pop.speed.x -= damp.x; pop.speed.y -= damp.y; } +} + + +void +blink_crosses(entt::registry& registry, const float dt) +{ auto crosses = registry.view<Cross>(); for (auto&& [entity, cross] : crosses.each()) { cross.timer += dt; @@ -119,15 +153,15 @@ Battle::update(const float dt) if (cross.timer > dphase) cross.timer -= dphase; } +} + + +void +animate_lines(entt::registry& registry, const float dt, const float time_factor) +{ auto lines = registry.view<Line>(); for (auto&& [entity, line] : lines.each()) line.position += (1.0 + line.hlength) / line.duration * dt * time_factor; - balance.update(registry); - ImGui::SetNextWindowPos({GetScreenWidth()/2.0f, GetScreenHeight()-100.0f}, ImGuiCond_Once, {0.5f, 0.5f}); - ImGui::SetNextWindowSize({240.0f, 0.0f}, ImGuiCond_Once); - if (ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_NoFocusOnAppearing)) - time_controls("TimeControls", time_factor); - ImGui::End(); } |