aboutsummaryrefslogtreecommitdiff
path: root/Tile.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-23 19:16:19 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-23 19:16:19 +0200
commit1e0a52b03fe655d7073ef20703dbb2e7646f74d3 (patch)
treef1709c2e9565d78c791653e71e6a4b26b3138423 /Tile.cpp
parent277157b3e06b2deeacbdbc8bf6190de19f88169d (diff)
add XY struct for 2d points and offsets
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;
+ }
}