Fog of War works but it's in the wrong place and needs to be based on light.

This commit is contained in:
Zed A. Shaw 2025-07-20 01:34:39 -04:00
parent 2802a44ba4
commit d264760405
5 changed files with 33 additions and 14 deletions

View file

@ -526,7 +526,7 @@ bool System::inventory_occupied(GameLevel& level, Entity container_id, const std
}
void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) {
void System::draw_map(GameLevel& level, Matrix& grid, Matrix& fow, EntityGrid& entity_map) {
World &world = *level.world;
Map &map = *level.map;
size_t view_x = matrix::width(grid) - 1;
@ -547,7 +547,7 @@ void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) {
size_t tile_y = size_t(it.y) + cam_orig.y;
size_t tile_x = size_t(it.x) + cam_orig.x;
if(matrix::inbounds(tiles, tile_x, tile_y)) {
if(matrix::inbounds(tiles, tile_x, tile_y) && fow[tile_y][tile_x]) {
size_t tid = tiles[tile_y][tile_x];
grid[it.y][it.x] = tile_set[tid];
} else {
@ -558,11 +558,15 @@ void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) {
// then get the enemy/item/device tiles and fill those in
world.query<Position, Tile>([&](auto, auto &pos, auto &entity_glyph) {
// BUG: don't I have a within bounds macro somewhere?
if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x
&& pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y)
if(pos.location.x >= cam_orig.x
&& pos.location.x <= cam_orig.x + view_x
&& pos.location.y >= cam_orig.y
&& pos.location.y <= cam_orig.y + view_y)
{
Point view_pos = map.map_to_camera(pos.location, cam_orig);
entity_map.insert_or_assign(view_pos, entity_glyph.display);
if(fow[pos.location.y][pos.location.x]) {
Point view_pos = map.map_to_camera(pos.location, cam_orig);
entity_map.insert_or_assign(view_pos, entity_glyph.display);
}
}
});
}