From 8cf389aaf748c77aecda0b3a3773c45053b0f231 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 13:02:38 +0200 Subject: implement all ALGA features --- Artist.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'Artist.cpp') diff --git a/Artist.cpp b/Artist.cpp index 6d95542..7bcd04b 100644 --- a/Artist.cpp +++ b/Artist.cpp @@ -3,15 +3,21 @@ #include "Artist.h" #include "Museum.h" +using namespace std; + Artist::Artist(Museum & museum, ArtistData data) : museum(museum) { this->data = data; this->data.vx /= 5; this->data.vy /= 5; } -void Artist::update() { - this->update_edge_collision(); - this->update_movement(); +void Artist::update(bool tick) { + if (tick) { + this->update_edge_collision(); + this->update_movement(); + } + // Artist<->Artist collisions are marked by CollisionChecker + this->update_path_collision(); this->update_color(); } @@ -38,6 +44,17 @@ void Artist::update_movement() { if (abs(int(last_y) - int(this->data.y)) > 0) this->step = true; } +void Artist::update_path_collision() { + PathfindingContext & ctx = this->museum.pathfinding; + if (!ctx.has_collision) return; + Pathfinder & solver = ctx.get_solver(); + bool is_solution = solver.is_solution({ + static_cast(this->data.x), + static_cast(this->data.y), + }); + if (is_solution) this->colliding = true; +} + void Artist::update_color() { if (this->colliding) { this->color = { -- cgit v1.2.3