aboutsummaryrefslogtreecommitdiff
path: root/Tile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tile.cpp')
-rw-r--r--Tile.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/Tile.cpp b/Tile.cpp
index cd1e820..92da9e7 100644
--- a/Tile.cpp
+++ b/Tile.cpp
@@ -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;
+ }
}