Tried to set the background color in the ftxui canvas and weirdly it started doing almost what I want with lighting, but I didn't write any code to do that. There's some bug in how I'm doing it that's causing it to set the colors...correctly. Must find out why.

This commit is contained in:
Zed A. Shaw 2024-11-23 23:11:20 -05:00
parent fb1fd9d8bc
commit 1bb04b4562
5 changed files with 55 additions and 13 deletions

19
gui.cpp
View file

@ -32,6 +32,7 @@ using namespace ftxui;
using namespace components;
GUI::GUI(DinkyECS::World &world, Map& game_map) :
$darkness({1600,800}),
$game_map(game_map),
$log({{"Welcome to the game!"}}),
$status_ui(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
@ -46,6 +47,10 @@ GUI::GUI(DinkyECS::World &world, Map& game_map) :
$sounds.load("combat_player_hit", "combat_player_hit.mp3");
$sounds.load("combat_enemy_hit", "combat_enemy_hit.mp3");
$sounds.load("combat_miss", "combat_miss.mp3");
$light_test.loadFromFile("./assets/light_test.png");
$darkness.setTexture(&$light_test);
resize_map(MAX_FONT_SIZE);
}
@ -220,8 +225,8 @@ bool GUI::handle_ui_events() {
void GUI::run_systems() {
auto player = $world.get_the<Player>();
System::enemy_pathing($world, $game_map, player);
System::motion($world, $game_map);
System::enemy_pathing($world, $game_map, player);
System::collision($world, player);
System::death($world);
}
@ -240,11 +245,13 @@ void GUI::shake() {
void GUI::render_scene() {
$renderer.clear();
$status_ui.render();
$renderer.draw($status_ui);
$map_view.render();
$renderer.draw($map_view);
$status_ui.render();
$renderer.draw($status_ui);
$renderer.display();
}
@ -253,16 +260,16 @@ int GUI::main() {
create_renderer();
run_systems();
while($renderer.is_open()) {
do {
render_scene();
if(handle_ui_events()) {
run_systems();
handle_world_events();
}
handle_world_events();
std::this_thread::sleep_for(10ms);
}
} while($renderer.is_open());
return 0;
}