Exploring raycasters and possibly make a little "doom like" game based on it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
raycaster/main_ui.cpp

74 lines
2.0 KiB

#include "main_ui.hpp"
#include "components.hpp"
namespace gui {
using namespace components;
MainUI::MainUI(sf::RenderWindow& window, GameLevel level, TexturePack& textures) :
$window(window),
$level(level),
$textures(textures),
$overlay_ui($level, $textures)
{
$window.setVerticalSyncEnabled(VSYNC);
$window.setFramerateLimit(FRAME_LIMIT);
}
void MainUI::debug() {
auto& dbg = $level.world->get_the<Debug>();
dbg.FPS = !dbg.FPS;
dbg.PATHS = !dbg.PATHS;
if(dbg.FPS) {
// it's on now, enable things
auto player = $level.world->get_the<Player>();
auto& player_combat = $level.world->get<Combat>(player.entity);
player_combat.hp = player_combat.max_hp;
$overlay_ui.show_text("top_left", "STATS");
} else {
// it's off now, close it
$overlay_ui.close_text("top_left");
}
}
void MainUI::draw_stats() {
auto player = $level.world->get_the<Player>();
auto player_combat = $level.world->get<Combat>(player.entity);
std::string stats = fmt::format("STATS\n"
"HP: {}\n"
"mean:{:>8.5}\n"
"sdev: {:>8.5}\n"
"min: {:>8.5}\n"
"max: {:>8.5}\n"
"count:{:<10}\n\n"
"VSync? {}\n"
"FR Limit: {}\n"
"Debug? {}\n\n",
player_combat.hp, $stats.mean(), $stats.stddev(), $stats.min,
$stats.max, $stats.n, VSYNC,
FRAME_LIMIT, DEBUG_BUILD);
$overlay_ui.update_text("top_left", stats);
}
void MainUI::draw_blood() {
auto player = $level.world->get_the<Player>();
auto player_combat = $level.world->get<Combat>(player.entity);
if(float(player_combat.hp) / float(player_combat.max_hp) < 0.5) {
$overlay_ui.show_sprite("middle", "blood_splatter");
} else {
$overlay_ui.close_sprite("middle");
}
}
void MainUI::render() {
$overlay_ui.render();
}
void MainUI::draw() {
$overlay_ui.draw($window);
auto debug = $level.world->get_the<Debug>();
if(debug.FPS) draw_stats();
}
}