Now have color and display char coming from assets/tiles.json but lighting still needs work.

This commit is contained in:
Zed A. Shaw 2024-12-24 02:56:17 -05:00
parent 7fe6ad174d
commit 89e31279be
4 changed files with 70 additions and 36 deletions

View file

@ -176,7 +176,6 @@ void System::draw_entities(DinkyECS::World &world, Map &game_map, const Matrix &
void System::draw_map(DinkyECS::World &world, Map &game_map, const Matrix &lighting, ftxui::Canvas &canvas, size_t view_x, size_t view_y) {
const auto& debug = world.get_the<Debug>();
const auto& config = world.get_the<MapConfig>();
const auto& player = world.get_the<Player>();
const auto& player_position = world.get<Position>(player.entity);
Point start = game_map.center_camera(player_position.location, view_x, view_y);
@ -188,15 +187,10 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, const Matrix &light
for(size_t y = 0; y < end_y; ++y) {
for(size_t x = 0; x < end_x; ++x) {
const string& tile = tiles.at(start.x+x, start.y+y);
const TileCell& tile = tiles.at(start.x+x, start.y+y);
int light_value = debug.LIGHT ? 160 : lighting[start.y+y][start.x+x];
if(tile == config.WALL_TILE) {
canvas.DrawText(x * 2, y * 4, config.WALL_TILE, [light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(230, 20, 10);
pixel.background_color = Color::HSV(230, 20, light_value / 2);
});
} else if(debug.PATHS) {
if(debug.PATHS) {
int dnum = paths[start.y+y][start.x+x];
string num = format("{:x}", dnum);
num = num.size() > 2 ? "*" : num;
@ -205,15 +199,10 @@ void System::draw_map(DinkyECS::World &world, Map &game_map, const Matrix &light
pixel.foreground_color = Color::HSV(dnum * 20, 150, 200);
pixel.background_color = Color::HSV(30, 20, light_value / 5);
});
} else if(tile == config.WATER_TILE) {
canvas.DrawText(x * 2, y * 4, tile, [light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(132, 200, std::min(int(light_value * 1.5), 200));
pixel.background_color = Color::HSV(147, 220, light_value / 1.5);
});
} else {
canvas.DrawText(x * 2, y * 4, tile, [light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(80, 100, light_value / 1.5);
pixel.background_color = Color::HSV(30, 20, light_value / 3);
canvas.DrawText(x * 2, y * 4, tile.display, [tile, light_value](auto &pixel) {
pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, light_value);
pixel.background_color = Color::HSV(tile.bg_h, tile.bg_s, light_value / 2);
});
}
}