diff options
Diffstat (limited to 'Tile.cpp')
-rw-r--r-- | Tile.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -28,14 +28,15 @@ void Tile::update() { this->behavior->update(*this); } -Tile * Tile::get_neighbor(int dx, int dy) { - Canvas & canvas = this->museum.canvas; - int x = this->data.x + dx; - int y = this->data.y + dy; - if (x < 0) return nullptr; - if (x >= canvas.data.columns) return nullptr; - if (y < 0) return nullptr; - if (y >= canvas.data.columns) return nullptr; - return &canvas.get_tile(x, y); +Tile * Tile::get_neighbor(const XY & offset) { + XY here { + .x = static_cast<int>(this->data.x), + .y = static_cast<int>(this->data.y), + }; + try { + return &this->museum.canvas.get_tile(here + offset); + } catch (...) { + return nullptr; + } } |