From feaf272efad381414c6ee76c0cd4bf929e8087ae Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 13 Oct 2024 17:43:36 +0200 Subject: WIP --- Canvas.cpp | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'Canvas.cpp') diff --git a/Canvas.cpp b/Canvas.cpp index 723ebff..d4b4670 100644 --- a/Canvas.cpp +++ b/Canvas.cpp @@ -3,18 +3,23 @@ #include "Canvas.h" #include "util.h" +#include "Museum.h" using namespace std; +Canvas::Canvas(Museum & museum) : museum(museum) { } + Tile & Canvas::get_tile(unsigned x, unsigned y) { return *this->tiles[this->pos_to_index(x, y)]; } -void Canvas::set_tile(unsigned x, unsigned y, TileData t) { +void Canvas::set_tile(unsigned x, unsigned y, TileData data) { size_t index = this->pos_to_index(x, y); if (this->tiles[index] != nullptr) delete this->tiles[index]; - this->tiles[index] = new Tile(t); + this->tiles[index] = new Tile(this->museum, data); + this->tiles[index]->x = x; + this->tiles[index]->y = y; } size_t Canvas::pos_to_index(unsigned x, unsigned y) { @@ -22,15 +27,20 @@ size_t Canvas::pos_to_index(unsigned x, unsigned y) { return index; } -void Canvas::update(Museum & museum) { +void Canvas::update() { + this->update_steps(); + this->update_tiles(); } void Canvas::set_data(CanvasData data) { this->data = data; this->tiles.resize(this->data.rows * this->data.columns); - for (size_t i = 0; i < this->tiles.size(); i++) { - if (this->tiles[i] != nullptr) continue; - this->tiles[i] = new Tile(); + for (size_t y = 0; y < this->data.rows; y++) { + for (size_t x = 0; x < this->data.columns; x++) { + if (this->tiles[this->pos_to_index(x, y)] != nullptr) + continue; + this->set_tile(x, y, {}); + } } } @@ -64,3 +74,20 @@ string Canvas::to_string(bool truecolor) { return out; } +void Canvas::update_steps() { + for (size_t i = 0; i < this->museum.people.artists_size(); i++) { + Artist & artist = this->museum.people.get_artist(i); + if (artist.step == false) continue; + artist.step = false; + + this->get_tile(artist.data.x, artist.data.y).step(); + } +} + +void Canvas::update_tiles() { + for (Tile * tile : this->tiles) { + if (tile == nullptr) continue; + tile->update(); + } +} + -- cgit v1.2.3