diff options
-rw-r--r-- | kurator/CMakeLists.txt | 1 | ||||
-rw-r--r-- | kurator/src/Battle.cpp | 27 | ||||
-rw-r--r-- | kurator/src/components.h | 11 | ||||
-rw-r--r-- | kurator/src/lines.cpp | 36 | ||||
-rw-r--r-- | kurator/src/lines.h | 28 |
5 files changed, 66 insertions, 37 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 17d3939..82f0a3f 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable( src/colors.cpp src/ForceBalance.cpp src/Grid.cpp + src/lines.cpp src/main.cpp src/markers.cpp src/Pause.cpp diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp index 0918e30..9df0b01 100644 --- a/kurator/src/Battle.cpp +++ b/kurator/src/Battle.cpp @@ -19,6 +19,7 @@ #include "components.h" #include "Grid.h" +#include "lines.h" #include "markers.h" #include "Pause.h" #include "PopupEmitter.h" @@ -78,7 +79,6 @@ time_controls(const char* id, float& time_factor) static void progress_timers(sim::State& ctx); static void move_ui_pops(sim::State& ctx); static void blink_crosses(sim::State& ctx); -static void animate_lines(sim::State& ctx); void @@ -149,17 +149,7 @@ blink_crosses(sim::State& ctx) } -void -animate_lines(sim::State& ctx) -{ - auto lines = ctx.registry.view<Line>(); - for (auto&& [entity, line] : lines.each()) - line.position += (1.0 + line.hlength) / line.duration * ctx.clock.dt; -} - - static void draw_crosses(const sim::State& ctx); -static void draw_lines(const sim::State& ctx); static void draw_pops(const sim::State& ctx); @@ -201,21 +191,6 @@ draw_crosses(const sim::State& ctx) void -draw_lines(const sim::State& ctx) -{ - auto lines = ctx.registry.view<Line>(); - for (const auto& [entity, line] : lines.each()) { - const auto diff = line.end - line.start; - const auto fstart = line.position - line.hlength; - const auto fend = line.position + line.hlength; - const auto start = ctx.camera.to_screen(line.start + diff.scale(fstart > 0.0 ? fstart : 0.0)); - const auto end = ctx.camera.to_screen(line.start + diff.scale(fend > 1.0 ? 1.0 : fend)); - DrawLine(start.x, start.y, end.x, end.y, line.color); - } -} - - -void draw_pops(const sim::State& ctx) { auto pops = ctx.registry.view<CenteredText, sim::Transform, UIOffset>(); diff --git a/kurator/src/components.h b/kurator/src/components.h index 41f0c67..51e91e3 100644 --- a/kurator/src/components.h +++ b/kurator/src/components.h @@ -39,17 +39,6 @@ struct PopMove }; -struct Line -{ - Color color; - engine::Point start; - engine::Point end; - double hlength; - double duration; - double position = 0.0; -}; - - struct Cross { double phase; diff --git a/kurator/src/lines.cpp b/kurator/src/lines.cpp new file mode 100644 index 0000000..50c7138 --- /dev/null +++ b/kurator/src/lines.cpp @@ -0,0 +1,36 @@ +#include "lines.h" + +#include <raylib.h> + +#include <kurator/sim/State.h> + + +namespace kurator +{ + + +void +animate_lines(sim::State& ctx) +{ + auto lines = ctx.registry.view<Line>(); + for (auto&& [entity, line] : lines.each()) + line.position += (1.0 + line.hlength) / line.duration * ctx.clock.dt; +} + + +void +draw_lines(const sim::State& ctx) +{ + auto lines = ctx.registry.view<Line>(); + for (const auto& [entity, line] : lines.each()) { + const auto diff = line.end - line.start; + const auto fstart = line.position - line.hlength; + const auto fend = line.position + line.hlength; + const auto start = ctx.camera.to_screen(line.start + diff.scale(fstart > 0.0 ? fstart : 0.0)); + const auto end = ctx.camera.to_screen(line.start + diff.scale(fend > 1.0 ? 1.0 : fend)); + DrawLine(start.x, start.y, end.x, end.y, line.color); + } +} + + +} // namespace kurator diff --git a/kurator/src/lines.h b/kurator/src/lines.h new file mode 100644 index 0000000..a9bed72 --- /dev/null +++ b/kurator/src/lines.h @@ -0,0 +1,28 @@ +#pragma once + +#include <raylib.h> + +#include <kurator/engine/Point.h> +#include <kurator/sim/State.h> + + +namespace kurator +{ + + +struct Line +{ + Color color; + engine::Point start; + engine::Point end; + double hlength; + double duration; + double position = 0.0; +}; + + +void animate_lines(sim::State& ctx); +void draw_lines(const sim::State& ctx); + + +} // namespace kurator |