From 6174df5ec733056ae773fdb69e01037f22cb9569 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 26 Nov 2024 05:03:49 -0500 Subject: [PATCH] Lighting now works, now to get multiple lights. --- main.cpp | 2 +- map.cpp | 4 ++-- status.txt | 4 ---- systems.cpp | 39 +++++++++++++++++++++++++++++++++------ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/main.cpp b/main.cpp index 452796b..500ef2a 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ void configure_world(DinkyECS::World &world, Map &game_map) { world.set(player.entity, {100, 10}); world.set(player.entity, {config.PLAYER_TILE}); world.set(player.entity, {5}); - world.set(player.entity, {200}); + world.set(player.entity, {150}); auto enemy = world.entity(); world.set(enemy, {game_map.place_entity(1)}); diff --git a/map.cpp b/map.cpp index b678ca7..30fdbdf 100644 --- a/map.cpp +++ b/map.cpp @@ -192,9 +192,9 @@ bool Map::neighbors(Point &out, bool greater) { // BUG: sometimes cur is in a wall so finding neighbors fails for(size_t i = 0; i < dirs.size(); ++i) { Point dir = dirs[i]; - int target = inmap(dir.x, dir.y) ? $paths[dir.y][dir.x] : 1000; + int target = inmap(dir.x, dir.y) ? $paths[dir.y][dir.x] : $limit; - if(target == 1000) continue; // skip unpathable stuff + if(target == $limit) continue; // skip unpathable stuff int diff = cur - target; diff --git a/status.txt b/status.txt index 1df2ebd..f878184 100644 --- a/status.txt +++ b/status.txt @@ -1,12 +1,8 @@ TODAY'S GOAL: -* Use d-map to create a mapping of light strength and use that to alter the value of colors in the map. -* Make it possible to visualize the d-map when I need to. - TODO: * Neighbors needs a rewrite * Neighbors algo isn't using greater parameter -* Look in system.cpp::draw_map for notes on a Lighting system. * Write a method for renderer that can translate coordinates. * Can std::any be defaulted to a noop in the events? * Save file isn't saving gold. diff --git a/systems.cpp b/systems.cpp index 143e926..41b28b5 100644 --- a/systems.cpp +++ b/systems.cpp @@ -16,17 +16,39 @@ using namespace fmt; using namespace components; using ftxui::Color; +const int LIGHT_MIN = 20; +const int LIGHT_MAX = 160; + void System::lighting(DinkyECS::World &world, Map &game_map, Player &player) { const auto& player_light = world.get(player.entity); auto &paths = game_map.paths(); auto &lighting = game_map.lighting(); - const int LIGHT_MIN = 10; - const int LIGHT_MAX = 110; + std::vector has_light; for(size_t x = 0; x < game_map.width(); ++x) { for(size_t y = 0; y < game_map.height(); ++y) { int dnum = paths[y][x]; - lighting[y][x] = std::clamp(255 - (dnum * player_light.strength), LIGHT_MIN, LIGHT_MAX); + int light = std::clamp(255 - (dnum * player_light.strength), LIGHT_MIN, LIGHT_MAX); + lighting[y][x] = light; + + if(light > LIGHT_MIN) { + has_light.push_back({x,y}); + } + } + } + + + const int UNPATH = game_map.limit(); + + for(auto point : has_light) { + for(int i = -1; i <= 1; i++) { + for(int j = -1; j <= 1; j++) { + if(!game_map.inmap(point.x+i, point.y+j)) continue; + + if(paths[point.y+j][point.x+i] == UNPATH) { + lighting[point.y+j][point.x+i] = LIGHT_MAX; + } + } } } } @@ -183,9 +205,14 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv int light_value = lighting[start.y+y][start.x+x]; if(tile == config.WALL_TILE) { - canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [](auto &pixel) { - pixel.foreground_color = Color::HSV(230, 20, 10); - pixel.background_color = Color::HSV(230, 20, 30); + canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [light_value](auto &pixel) { + if(light_value > LIGHT_MIN) { + pixel.foreground_color = Color::HSV(230, 20, 10); + pixel.background_color = Color::HSV(230, 20, light_value / 2); + } else { + pixel.foreground_color = Color::HSV(230, 20, 20); + pixel.background_color = Color::HSV(230, 20, 30); + } }); } else if(DEBUG_MAP) { int dnum = paths[start.y+y][start.x+x];