We now have a full map that's basically the same mapping system from Roguish. There's a bug right now where it needs you to move once to calc the light and it's not being centered, but it does work.
This commit is contained in:
parent
55b67dcf5d
commit
d798d154ae
22 changed files with 1270 additions and 47 deletions
25
systems.cpp
25
systems.cpp
|
@ -12,6 +12,7 @@ using std::string;
|
|||
using namespace fmt;
|
||||
using namespace components;
|
||||
using lighting::LightSource;
|
||||
using ftxui::Color;
|
||||
|
||||
void System::lighting(GameLevel &level) {
|
||||
auto &light = *level.lights;
|
||||
|
@ -221,3 +222,27 @@ void System::plan_motion(DinkyECS::World& world, Point move_to) {
|
|||
motion.dx = move_to.x - player_position.location.x;
|
||||
motion.dy = move_to.y - player_position.location.y;
|
||||
}
|
||||
|
||||
/*
|
||||
* This one is called inside the MapViewUI very often so
|
||||
* just avoide GameMap unlike the others.
|
||||
*/
|
||||
void System::draw_entities(DinkyECS::World &world, Map &map, const Matrix &lights, ftxui::Canvas &canvas, const Point &cam_orig, size_t view_x, size_t view_y) {
|
||||
auto &tiles = map.tiles();
|
||||
|
||||
world.query<Position, Tile>([&](auto &ent[[maybe_unused]], auto &pos, auto &tile) {
|
||||
if(pos.location.x >= cam_orig.x && pos.location.x <= cam_orig.x + view_x
|
||||
&& pos.location.y >= cam_orig.y && pos.location.y <= cam_orig.y + view_y) {
|
||||
Point loc = map.map_to_camera(pos.location, cam_orig);
|
||||
|
||||
float light_value = lights[pos.location.y][pos.location.x] * PERCENT;
|
||||
const TileCell& cell = tiles.at(pos.location.x, pos.location.y);
|
||||
|
||||
// the 2 and 4 are from ftxui::Canvas since it does a kind of "subpixel" drawing
|
||||
canvas.DrawText(loc.x*2, loc.y*4, tile.chr, [tile, light_value, cell](auto &pixel) {
|
||||
pixel.foreground_color = Color::HSV(tile.fg_h, tile.fg_s, tile.fg_v * light_value);
|
||||
pixel.background_color = Color::HSV(cell.bg_h, cell.bg_s, cell.bg_v * light_value);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue