Systems now control most of the game's operations and a lot of the rendering logic, this now brings in a camera so maps can be larger than the viewport.

This commit is contained in:
Zed A. Shaw 2024-10-17 21:43:19 -04:00
parent e42647d727
commit da64e526c4
5 changed files with 62 additions and 36 deletions

18
map.hpp
View file

@ -3,12 +3,18 @@
#include <utility>
#include <string>
#include <random>
#include <algorithm>
#include <fmt/core.h>
#define INV_WALL 0
#define INV_SPACE 1
#define WALL_VALUE 1
#define SPACE_VALUE 0
#define WALL_TILE "█"
#define FLOOR_TILE "·"
#define PLAYER_TILE "☺"
#define ENEMY_TILE "Ω"
struct Point {
size_t x = 0;
@ -81,4 +87,14 @@ public:
void set_door(Room &room, int value);
void dump();
Point place_entity(size_t room_index);
Point map_to_camera(const Point &loc, const Point &cam_orig) {
return {loc.x - cam_orig.x, loc.y - cam_orig.y};
}
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));
return {start_x, start_y};
}
};