diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-23 19:16:19 +0200 | 
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-23 19:16:19 +0200 | 
| commit | 1e0a52b03fe655d7073ef20703dbb2e7646f74d3 (patch) | |
| tree | f1709c2e9565d78c791653e71e6a4b26b3138423 /Tile.cpp | |
| parent | 277157b3e06b2deeacbdbc8bf6190de19f88169d (diff) | |
add XY struct for 2d points and offsets
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; +	}  } |