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/boss_fight_ui.cpp

82 lines
2.4 KiB

#include "boss_fight_ui.hpp"
#include "easings.hpp"
namespace gui {
BossFightUI::BossFightUI() {
$status.position(0, 0, 300, SCREEN_HEIGHT);
$status.layout(
"[(150)status_1|(150)status_2]"
"[(150)status_3|(150)status_4]"
"[(150)status_5|(150)status_6]"
"[(150)status_7|(150)status_8]"
);
$overlay.position(300, 0, SCREEN_WIDTH - 300, SCREEN_HEIGHT);
$overlay.layout("[overlay_1|overlay_2|overlay_3|overlay_4]"
"[overlay_5|overlay_6|overlay_7|overlay_8]"
"[overlay_9|overlay_10|overlay_11|overlay_12]"
"[overlay_13|overlay_14|overlay_15|overlay_16]");
$boss_image = textures::get("boss_fight");
auto bounds = $boss_image.sprite->getLocalBounds();
$boss_image.sprite->setPosition({300 + bounds.size.x / 2, bounds.size.y / 2});
$boss_image.sprite->setOrigin({bounds.size.x / 2, bounds.size.y / 2});
}
void BossFightUI::init() {
$status.world().set_the<Background>({$status.$parser});
for(auto& [name, cell] : $status.cells()) {
auto button = $status.entity(name);
$status.set<Rectangle>(button, {});
$status.set<Clickable>(button, {
[this, name](auto, auto){ fmt::println("STATUS: {}", name); }
});
$status.set<Label>(button, {name});
}
$status.init();
for(auto& [name, cell] : $overlay.cells()) {
auto region = $overlay.entity(name);
$overlay.set<Clickable>(region, {
[this, name](auto, auto){ fmt::println("OVERLAY: {}", name); }
});
}
auto region = $overlay.entity("overlay_2");
$overlay.set<Label>(region, {"THE RAT KING!"});
$overlay.init();
}
void BossFightUI::bounce_boss(sf::RenderWindow& window) {
auto time = $clock.getElapsedTime();
float tick = ease::in_out_back(ease::sine(time.asSeconds()));
float scale = std::lerp(1.1, 1.3, tick);
$boss_image.sprite->setScale({scale, scale});
window.draw(*$boss_image.sprite);
}
void BossFightUI::render(sf::RenderWindow& window) {
if($boss_hit) {
bounce_boss(window);
} else {
window.draw(*$boss_image.sprite);
}
$status.render(window);
$overlay.render(window);
}
bool BossFightUI::mouse(float x, float y) {
if($status.mouse(x, y)) {
fmt::println("STATUS");
}
if($overlay.mouse(x, y)) {
fmt::println("OVERLAY");
$boss_hit = !$boss_hit;
}
return false;
}
}