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

@ -13,9 +13,8 @@
#include <fstream>
#include "palette.hpp"
constexpr const int map_width=13;
constexpr const int map_height=13;
constexpr const int MAP_WIDTH=13;
constexpr const int MAP_HEIGHT=13;
namespace gui {
using namespace components;
@ -25,7 +24,8 @@ namespace gui {
$level(level),
$map_render(std::make_shared<sf::RenderTexture>()),
$map_sprite($map_render->getTexture()),
$map_tiles(matrix::make(map_width, map_height))
$map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT)),
$fow(matrix::make($level.map->width(), $level.map->height()))
{
auto player = $level.world->get_the<Player>();
$player_display = $level.world->get<Tile>(player.entity).display;
@ -33,6 +33,7 @@ namespace gui {
void MapViewUI::update_level(GameLevel &level) {
$level = level;
$fow = matrix::make($level.map->width(), $level.map->height());
}
void MapViewUI::init() {
@ -44,7 +45,7 @@ namespace gui {
$gui.set<Rectangle>($log_to, {10, THEME.DARK_MID, THEME.BORDER_COLOR, 10});
$gui.set<Textual>($log_to, {L"Welcome to the Game!", 25, THEME.TEXT_COLOR, 10});
auto map_cell = lel::center(MAP_TILE_DIM * map_width, MAP_TILE_DIM * map_height, $gui.cell_for("map_grid"));
auto map_cell = lel::center(MAP_TILE_DIM * MAP_WIDTH, MAP_TILE_DIM * MAP_HEIGHT, $gui.cell_for("map_grid"));
$map_sprite.setPosition({(float)map_cell.x, (float)map_cell.y + 30});
$gui.init();
@ -62,7 +63,17 @@ namespace gui {
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
$gui.render(window);
System::draw_map($level, $map_tiles, $entity_map);
auto player = $level.world->get_the<components::Player>();
auto player_pos = $level.world->get<components::Position>(player.entity).location;
// NOTE: FoW is probably better done in the lighting system, because it illuminates where you've been. The light calcs could then simply set the light the player touches to 1 when it's run.
for(matrix::circle it{$fow, player_pos, 2.5}; it.next();) {
for(int x = it.left; x < it.right; x++) {
$fow[it.y][x] = 1;
}
}
System::draw_map($level, $map_tiles, $fow, $entity_map);
System::render_map($map_tiles, $entity_map, *$map_render, compass_dir, $player_display);
$map_sprite.setTexture($map_render->getTexture(), true);
window.draw($map_sprite);

View file

@ -17,6 +17,7 @@ namespace gui {
std::shared_ptr<sf::RenderTexture> $map_render;
sf::Sprite $map_sprite;
matrix::Matrix $map_tiles;
matrix::Matrix $fow;
MapViewUI(GameLevel &level);
void init();