Fog of War now works fairly normally, but I think I'll have to do something so people don't live in the map. Probably something like hearing distance is increased because you're louder with a map out, and you can't see enemies on the map.

master
Zed A. Shaw 5 days ago
parent 2997dc363b
commit 6f91533950
  1. 2
      gui/map_view.cpp
  2. 9
      lights.cpp
  3. 3
      lights.hpp
  4. 12
      systems.cpp
  5. 2
      systems.hpp
  6. 2
      tests/map.cpp

@ -61,7 +61,7 @@ namespace gui {
void MapViewUI::render(sf::RenderWindow &window, int compass_dir) { void MapViewUI::render(sf::RenderWindow &window, int compass_dir) {
$gui.render(window); $gui.render(window);
System::draw_map($level, $map_tiles, $entity_map); System::draw_map($level, $map_tiles, $entity_map);
System::render_map($level, $map_tiles, $entity_map, *$map_render, compass_dir, $player_display); System::render_map($map_tiles, $entity_map, *$map_render, compass_dir, $player_display);
$map_sprite.setTexture($map_render->getTexture(), true); $map_sprite.setTexture($map_render->getTexture(), true);
window.draw($map_sprite); window.draw($map_sprite);
// $gui.debug_layout(window); // $gui.debug_layout(window);

@ -50,7 +50,6 @@ namespace lighting {
if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) { if($paths.$paths[it.y][it.x] == WALL_PATH_LIMIT) {
$lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y); $lightmap[it.y][it.x] = light_level(source.strength, 1.5f, point.x, point.y);
} }
$fow[it.y][it.x] = $lightmap[it.y][it.x];
} }
} }
} }
@ -74,6 +73,14 @@ namespace lighting {
$paths.set_target(at, value); $paths.set_target(at, value);
} }
void LightRender::update_fow(Point at, LightSource source) {
for(matrix::circle it{$lightmap, at, source.radius}; it.next();) {
for(auto x = it.left; x < it.right; x++) {
$fow[it.y][x] = $lightmap[it.y][x];
}
}
}
void LightRender::path_light(Matrix &walls) { void LightRender::path_light(Matrix &walls) {
$paths.compute_paths(walls); $paths.compute_paths(walls);
} }

@ -33,8 +33,7 @@ namespace lighting {
int light_level(int level, float distance, size_t x, size_t y); int light_level(int level, float distance, size_t x, size_t y);
void render_light(LightSource source, Point at); void render_light(LightSource source, Point at);
void render_square_light(LightSource source, Point at, PointList &has_light); void render_square_light(LightSource source, Point at, PointList &has_light);
void render_compass_light(LightSource source, Point at, PointList &has_light); void update_fow(Point player_pos, LightSource source);
void render_circle_light(LightSource source, Point at, PointList &has_light);
Matrix &lighting() { return $lightmap; } Matrix &lighting() { return $lightmap; }
Matrix &paths() { return $paths.paths(); } Matrix &paths() { return $paths.paths(); }
}; };

@ -36,9 +36,14 @@ void System::lighting(GameLevel &level) {
light.path_light(map.walls()); light.path_light(map.walls());
world.query<Position, LightSource>([&](auto, auto &position, auto &lightsource) { world.query<Position, LightSource>([&](auto ent, auto &position, auto &lightsource) {
light.render_light(lightsource, position.location); light.render_light(lightsource, position.location);
if(ent == level.player) {
light.update_fow(position.location, lightsource);
}
}); });
} }
void System::generate_paths(GameLevel &level) { void System::generate_paths(GameLevel &level) {
@ -572,15 +577,12 @@ void System::draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map) {
}); });
} }
void System::render_map(GameLevel& level, Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) { void System::render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display) {
sf::Vector2i tile_sprite_dim{MAP_TILE_DIM,MAP_TILE_DIM}; sf::Vector2i tile_sprite_dim{MAP_TILE_DIM,MAP_TILE_DIM};
unsigned int width = matrix::width(tiles); unsigned int width = matrix::width(tiles);
unsigned int height = matrix::height(tiles); unsigned int height = matrix::height(tiles);
sf::Vector2u dim{width * tile_sprite_dim.x, height * tile_sprite_dim.y}; sf::Vector2u dim{width * tile_sprite_dim.x, height * tile_sprite_dim.y};
auto render_size = render.getSize(); auto render_size = render.getSize();
Matrix &fow = level.lights->$fow;
(void)level;
(void)fow;
if(render_size.x != width || render_size.y != height) { if(render_size.x != width || render_size.y != height) {
bool worked = render.resize(dim); bool worked = render.resize(dim);

@ -40,5 +40,5 @@ namespace System {
bool inventory_occupied(GameLevel& level, Entity container_id, const std::string& name); bool inventory_occupied(GameLevel& level, Entity container_id, const std::string& name);
void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map); void draw_map(GameLevel& level, Matrix& grid, EntityGrid& entity_map);
void render_map(GameLevel& level, Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display); void render_map(Matrix& tiles, EntityGrid& entity_map, sf::RenderTexture& render, int compass_dir, wchar_t player_display);
} }

@ -101,7 +101,7 @@ TEST_CASE("map image test", "[map-sprite]") {
player_pos.location.x = it.x; player_pos.location.x = it.x;
player_pos.location.y = it.y; player_pos.location.y = it.y;
System::draw_map(level, map_tiles, entity_map); System::draw_map(level, map_tiles, entity_map);
System::render_map(level, map_tiles, entity_map, *render, 2, player_display); System::render_map(map_tiles, entity_map, *render, 2, player_display);
#ifdef TEST_RENDER #ifdef TEST_RENDER
// confirm we get two different maps // confirm we get two different maps

Loading…
Cancel
Save