Lighting now works, now to get multiple lights.

main
Zed A. Shaw 1 week ago
parent 4ceacecfda
commit 6174df5ec7
  1. 2
      main.cpp
  2. 4
      map.cpp
  3. 4
      status.txt
  4. 39
      systems.cpp

@ -33,7 +33,7 @@ void configure_world(DinkyECS::World &world, Map &game_map) {
world.set<Combat>(player.entity, {100, 10});
world.set<Tile>(player.entity, {config.PLAYER_TILE});
world.set<Inventory>(player.entity, {5});
world.set<LightSource>(player.entity, {200});
world.set<LightSource>(player.entity, {150});
auto enemy = world.entity();
world.set<Position>(enemy, {game_map.place_entity(1)});

@ -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;

@ -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.

@ -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<LightSource>(player.entity);
auto &paths = game_map.paths();
auto &lighting = game_map.lighting();
const int LIGHT_MIN = 10;
const int LIGHT_MAX = 110;
std::vector<Point> 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];

Loading…
Cancel
Save