Now have a basic prototype lighting system.

This commit is contained in:
Zed A. Shaw 2024-11-25 02:32:16 -05:00
parent 1bb04b4562
commit a9217e8423
4 changed files with 65 additions and 48 deletions

View file

@ -159,27 +159,34 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, ftxui::Canvas &canv
// LIGHT: if tile is in light then color ++ otherwise --
// LIGHT: is put into the/a collision map and if a cell is a light's neighbor
// it gets brighter.
const int LIGHT_MIN = 30;
const int LIGHT_MAX = 180;
const int LIGHT_MIN = 10;
const int LIGHT_MAX = 110;
int light_strength = 100; // lower is stronger
Point light_at{start.x+x, start.y+y};
int dnum = paths[light_at.y][light_at.x];
int light_value = std::clamp(255 - (dnum * 75), LIGHT_MIN, LIGHT_MAX);
int light_value = std::clamp(255 - (dnum * light_strength), LIGHT_MIN, LIGHT_MAX);
// "WALL_TILE": "\u2591",
// "WALL_TILE": "\ua5b8",
if(tile == config.WALL_TILE) {
canvas.DrawText(x * 2, y * 4, tile, Color::HSV(230, 20, 20));
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);
});
} else if(DEBUG_MAP) {
string num = format("{:x}", dnum);
num = num.size() > 2 ? "*" : num;
canvas.DrawText(x * 2, y * 4, num, Color::HSV(dnum * 20, 150, light_value));
canvas.DrawText(x * 2, y * 4, num, [dnum, light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(dnum * 20, 150, 200);
pixel.background_color = Color::HSV(30, 20, light_value / 5);
});
} else {
// floor tile or similar
// BUG: no idea why this works but this actually implements decent light
canvas.DrawText(x * 2, y * 4, tile, [&, light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(30, light_value / 2, light_value);
pixel.background_color = Color::HSV(30, 20, light_value);
});
canvas.DrawText(x * 2, y * 4, tile, [light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(30, 40, light_value);
pixel.background_color = Color::HSV(30, 20, light_value / 5);
});
}
}
}