Initial fix of the crash with different map sizes but that's not the ultimate fix.

This commit is contained in:
Zed A. Shaw 2024-11-09 10:14:53 -05:00
parent 809ec9ed0d
commit 2dccc6b17b
2 changed files with 16 additions and 6 deletions

10
map.hpp
View file

@ -96,8 +96,14 @@ public:
}
Point center_camera(const Point &around, size_t view_x, size_t view_y) {
size_t start_x = std::clamp(int(around.x - view_x / 2), 0, int(width() - view_x));
size_t start_y = std::clamp(int(around.y - view_y / 2), 0, int(height() - view_y));
int high_x = int(width() - view_x);
int high_y = int(height() - view_y);
int center_x = int(around.x - view_x / 2);
int center_y = int(around.y - view_y / 2);
size_t start_x = std::clamp(center_x, 0, high_x);
size_t start_y = std::clamp(center_y, 0, high_y);
return {start_x, start_y};
}
};