diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-13 17:43:36 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-13 17:43:36 +0200 |
commit | feaf272efad381414c6ee76c0cd4bf929e8087ae (patch) | |
tree | cbdf4ffc206eba701ce39871562a60e889a9ccab /Canvas.cpp | |
parent | 4343c7cd36a19c03c4885dbf15aaa22fe51b4fe0 (diff) |
WIP
Diffstat (limited to 'Canvas.cpp')
-rw-r--r-- | Canvas.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
@@ -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(); + } +} + |