From 6e8aa483325f86983149ef4a99d6bc50e233341c Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 3 Mar 2025 12:44:26 -0500 Subject: [PATCH] BossFightUI now gets everything from a world and will be implemented like the rest of the game, but as a mini game. --- boss_fight_ui.cpp | 27 ++++++++++++--------------- boss_fight_ui.hpp | 8 ++++---- levelmanager.cpp | 23 ++++++++++++++++++----- stats.hpp | 1 - 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/boss_fight_ui.cpp b/boss_fight_ui.cpp index da982e8..f362869 100644 --- a/boss_fight_ui.cpp +++ b/boss_fight_ui.cpp @@ -5,9 +5,10 @@ namespace gui { using namespace guecs; - BossFightUI::BossFightUI(DinkyECS::World& world, std::string boss_name) - : $config(world.get_the()), - $boss_name(boss_name) + BossFightUI::BossFightUI(shared_ptr world, DinkyECS::Entity boss_id) + : $world(world), + $boss_id(boss_id), + $config(world->get_the()) { $status.position(0, 0, BOSS_VIEW_X, SCREEN_HEIGHT); $status.layout( @@ -24,15 +25,13 @@ namespace gui { "[overlay_9|overlay_10|overlay_12]" "[overlay_13|overlay_14|overlay_16]"); - $sounds = components::get($config.bosses[boss_name]); - $combat = components::get($config.bosses[boss_name]); - $weapon_hit_sound = $config.bosses[$boss_name]["weapon_sound"]; + $sounds = $world->get($boss_id); + $combat = $world->get($boss_id); } void BossFightUI::configure_sprite() { - auto& boss = $config.bosses[$boss_name]; - $sprite_config = components::get(boss); - $animation = components::get(boss); + $sprite_config = $world->get($boss_id); + $animation = $world->get($boss_id); $animation.texture_width = $sprite_config.width; $boss_image = textures::get($sprite_config.name); @@ -48,8 +47,10 @@ namespace gui { } void BossFightUI::configure_background() { - auto& boss = $config.bosses[$boss_name]; - $boss_background = textures::get(boss["background"]); + // FIX ME + // auto& config = $world->get_the(); + std::string boss_bg = "boss_fight_background"; + $boss_background = textures::get(boss_bg); $boss_background.sprite->setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); $status.world().set_the({$status.$parser}); } @@ -96,10 +97,6 @@ namespace gui { sound::play($sounds.attack); } - if(!sound::playing($weapon_hit_sound) && $animation.subframe > 1.2 && $animation.subframe < 1.5) { - sound::play($weapon_hit_sound); - } - $boss_image.sprite->setTextureRect(frame_rect); window.draw(*$boss_image.sprite); } diff --git a/boss_fight_ui.hpp b/boss_fight_ui.hpp index b434214..389f1af 100644 --- a/boss_fight_ui.hpp +++ b/boss_fight_ui.hpp @@ -19,19 +19,19 @@ namespace gui { public: sf::Clock $clock; bool $boss_hit = false; - std::string $weapon_hit_sound; components::Combat $combat; components::Sprite $sprite_config; components::Sound $sounds; components::Animation $animation; - components::GameConfig& $config; - std::string $boss_name; guecs::UI $status; guecs::UI $overlay; textures::SpriteTexture $boss_image; textures::SpriteTexture $boss_background; + std::shared_ptr $world = nullptr; + DinkyECS::Entity $boss_id; + components::GameConfig& $config; - BossFightUI(DinkyECS::World& world, std::string boss_name); + BossFightUI(std::shared_ptr world, DinkyECS::Entity boss_id); void init(); void render(sf::RenderWindow& window); diff --git a/levelmanager.cpp b/levelmanager.cpp index 91412fd..5d2112d 100644 --- a/levelmanager.cpp +++ b/levelmanager.cpp @@ -21,12 +21,9 @@ LevelScaling LevelManager::scale_level() { }; } -shared_ptr LevelManager::create_bossfight(shared_ptr prev_world) { - dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null."); - return make_shared(*prev_world, "RAT_KING"); -} -size_t LevelManager::create_level(shared_ptr prev_world) { +inline shared_ptr clone_load_world(shared_ptr prev_world) +{ auto world = make_shared(); if(prev_world != nullptr) { @@ -35,6 +32,22 @@ size_t LevelManager::create_level(shared_ptr prev_world) { save::load_configs(*world); } + return world; +} + +shared_ptr LevelManager::create_bossfight(shared_ptr prev_world) { + dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null."); + auto world = clone_load_world(prev_world); + auto& config = prev_world->get_the(); + auto& boss_data = config.bosses["RAT_KING"]; + auto boss_id = world->entity(); + components::configure_entity($components, *world, boss_id, boss_data["components"]); + + return make_shared(world, boss_id); +} + +size_t LevelManager::create_level(shared_ptr prev_world) { + auto world = clone_load_world(prev_world); auto scaling = scale_level(); auto map = make_shared(scaling.map_width, scaling.map_height); diff --git a/stats.hpp b/stats.hpp index 555c0f8..8ff9555 100644 --- a/stats.hpp +++ b/stats.hpp @@ -11,7 +11,6 @@ struct Stats { double min = 0.0; double max = 0.0; - inline void reset() { sum = 0; sumsq = 0;