diff options
Diffstat (limited to 'ViewController.cpp')
-rw-r--r-- | ViewController.cpp | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/ViewController.cpp b/ViewController.cpp index 40e624a..b1fd795 100644 --- a/ViewController.cpp +++ b/ViewController.cpp @@ -14,6 +14,7 @@ #include "TimeTravelCommand.h" #include "View.h" #include "Museum.h" +#include "Pathfinder.h" using namespace std; @@ -43,10 +44,10 @@ void ViewController::update_tiles() { for (int x = 0; x < this->museum.canvas.data.columns; x++) { Tile & tile = this->museum.canvas.get_tile({ x, y }); Rectangle rect = { - .x = static_cast<float>(x * scale), - .y = static_cast<float>(y * scale), - .width = static_cast<float>(scale - line_width), - .height = static_cast<float>(scale - line_width), + .x = x * scale, + .y = y * scale, + .width = scale, + .height = scale, }; this->view.fill_rect(rect, tile.color); } @@ -57,10 +58,10 @@ void ViewController::update_artists() { People & people = this->museum.people; for (Artist * artist : people.get_artists()) { Rectangle rect = { - .x = static_cast<float>(artist->data.x * scale), - .y = static_cast<float>(artist->data.y * scale), - .width = static_cast<float>(artist_size), - .height = static_cast<float>(artist_size), + .x = artist->data.x * scale, + .y = artist->data.y * scale, + .width = artist_size, + .height = artist_size, }; this->view.fill_rect(rect, artist->color); } @@ -68,26 +69,36 @@ void ViewController::update_artists() { void ViewController::draw_pathfinding_dot(const XY & point, const Color & color) { this->view.fill_rect(center({ - .x = static_cast<float>(point.x * scale), - .y = static_cast<float>(point.y * scale), - .width = static_cast<float>(pathfinding_size), - .height = static_cast<float>(pathfinding_size), + .x = point.x * scale, + .y = point.y * scale, + .width = pathfinding_size, + .height = pathfinding_size, }), color); } void ViewController::update_pathfinding() { - PathfindingContext & ctx = this->museum.pathfinding; - this->draw_pathfinding_dot(ctx.get_end(), { - .red = 0x00, - .green = 0x00, - .blue = 0xdd, - }); - this->draw_pathfinding_dot(ctx.get_start(), { - .red = 0xff, - .green = 0xff, - .blue = 0xff, - }); + + Pathfinder & solver = ctx.get_solver(); + for (int y = 0; y < this->museum.canvas.data.rows; y++) { + for (int x = 0; x < this->museum.canvas.data.columns; x++) { + if (!solver.is_visited({ x, y })) continue; + Rectangle rect = { + .x = x * scale, + .y = y * scale, + .width = scale, + .height = scale, + }; + this->view.draw_rect(rect, { 0, 0, 0 }, 2); + } + } + + const Pathfinder::Path & solution = solver.get_path(); + for (const XY & point : solution) { + this->draw_pathfinding_dot(point, { 0, 0, 0 }); + } + + this->draw_pathfinding_dot(ctx.get_start(), { 0xff, 0xff, 0xff }); } void ViewController::update_quadtree_recursive(QuadTreeCollisionChecker * tree) { |