BossFightUI is not managed by the level manager since it is kind of a new level, just with a different mini game.

This commit is contained in:
Zed A. Shaw 2025-03-03 11:15:49 -05:00
parent a3f6ba3c03
commit ca18422930
12 changed files with 49 additions and 67 deletions

View file

@ -3,9 +3,10 @@
#include "sound.hpp"
namespace gui {
BossFightUI::BossFightUI(GameLevel level, std::string boss_name)
: $level(level),
$config($level.world->get_the<components::GameConfig>()),
using namespace guecs;
BossFightUI::BossFightUI(DinkyECS::World& world, std::string boss_name)
: $config(world.get_the<components::GameConfig>()),
$boss_name(boss_name)
{
$status.position(0, 0, BOSS_VIEW_X, SCREEN_HEIGHT);
@ -24,6 +25,7 @@ namespace gui {
"[overlay_13|overlay_14|overlay_16]");
$sounds = components::get<components::Sound>($config.bosses[boss_name]);
$combat = components::get<components::Combat>($config.bosses[boss_name]);
$weapon_hit_sound = $config.bosses[$boss_name]["weapon_sound"];
}
@ -36,7 +38,7 @@ namespace gui {
$boss_image = textures::get($sprite_config.name);
sf::IntRect frame_rect{{0,0},{$sprite_config.width,$sprite_config.height}};
$boss_image.sprite->setTextureRect(frame_rect);
$boss_image.sprite->setScale($scale);
$boss_image.sprite->setScale({$sprite_config.scale, $sprite_config.scale});
auto bounds = $boss_image.sprite->getLocalBounds();
auto bg_bounds = $boss_background.sprite->getLocalBounds();
@ -60,7 +62,7 @@ namespace gui {
[this, name](auto, auto){ fmt::println("STATUS: {}", name); }
});
if(name == "main_status") {
$status.set<Textual>(button, {fmt::format("HP: {}", $boss_hp)});
$status.set<Textual>(button, {fmt::format("HP: {}", $combat.hp)});
} else {
$status.set<Label>(button, {"Attack"});
}
@ -86,7 +88,7 @@ namespace gui {
void BossFightUI::bounce_boss(sf::RenderWindow& window) {
sf::IntRect frame_rect{{0,0},{$sprite_config.width,$sprite_config.height}};
auto scale = $scale;
sf::Vector2f scale{$sprite_config.scale, $sprite_config.scale};
$animation.step(scale, frame_rect);
$boss_image.sprite->setScale(scale);
@ -111,7 +113,7 @@ namespace gui {
window.draw(*$boss_image.sprite);
}
if($boss_hp == 0) {
if($combat.hp == 0) {
$overlay.show_label("overlay_1", "YOU WON!");
$overlay.show_label("overlay_4", "CLICK TO CONTINUE...");
}
@ -129,18 +131,9 @@ namespace gui {
$animation.play();
sound::play("Sword_Hit_1");
$boss_hit = !$boss_hit;
$boss_hp--;
$combat.hp--;
}
return false;
}
void BossFightUI::update_level(GameLevel &level) {
$level = level;
$boss_hp = 10 * $level.index + 1; // make him stronger
$boss_hit = false;
$overlay.close<Label>("overlay_1");
$overlay.close<Label>("overlay_4");
init();
}
}