diff --git a/assets/stories.json b/assets/stories.json new file mode 100644 index 0000000..e7f444a --- /dev/null +++ b/assets/stories.json @@ -0,0 +1,27 @@ +{ + "rat_king": + {"_type": "Storyboard", + "image": "test_story", + "audio": "rat_king_fight", + "layout": [ + "[a|b|c1]", + "[d|e|c2]", + "[g|h|i]" + ], + "beats": [ + ["00:00", "a","pan"], + ["00:06", "a","pan"], + ["00:13", "b","pan"], + ["00:19", "g","pan"], + ["00:25", "h","pan"], + ["00:29", "h","bounce"], + ["00:31", "c1","pan"], + ["00:34", "c2","pan"], + ["00:39", "d","bounce"], + ["00:44", "e","shake"], + ["00:48", "i","pan"], + ["00:53", "i","shake"], + ["00:55", "i","bounce"] + ] + } +} diff --git a/assets/story/rat_king_fight.jpg b/assets/story/rat_king_fight.jpg new file mode 100644 index 0000000..0a9a921 Binary files /dev/null and b/assets/story/rat_king_fight.jpg differ diff --git a/boss/fight.cpp b/boss/fight.cpp index ddb1373..62771bf 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -3,10 +3,10 @@ #include "animation.hpp" namespace boss { - Fight::Fight(shared_ptr world, Entity boss_id) : + Fight::Fight(shared_ptr world, Entity boss_id, Entity player_id) : $world(world), $boss_id(boss_id), - $ui(world->get($boss_id), boss_id) + $ui(world, boss_id, player_id) { $ui.init(); } @@ -88,6 +88,7 @@ namespace boss { $ui.move_actor("player", player_pos); int attack_id = std::any_cast(data); boss::System::combat($world, $boss_id, attack_id); + $ui.update_stats(); state(State::PLAYER_TURN); } break; default: diff --git a/boss/fight.hpp b/boss/fight.hpp index 9961b8c..4efb0c4 100644 --- a/boss/fight.hpp +++ b/boss/fight.hpp @@ -26,7 +26,7 @@ namespace boss { sf::Vector2f mouse_pos{0,0}; int run = 0; - Fight(shared_ptr world, DinkyECS::Entity boss_id); + Fight(shared_ptr world, Entity boss_id, Entity player_id); bool handle_mouse(gui::Event ev); bool event(gui::Event ev, std::any data); diff --git a/boss/system.cpp b/boss/system.cpp index 8018147..2c33f50 100644 --- a/boss/system.cpp +++ b/boss/system.cpp @@ -46,7 +46,7 @@ namespace boss { dbc::check(world->has(boss_id), "boss doesn't have an AI"); - return make_shared(world, boss_id); + return make_shared(world, boss_id, level.player); } void System::combat(std::shared_ptr world, DinkyECS::Entity boss_id, int attack_id) { @@ -55,8 +55,8 @@ namespace boss { dbc::check(world->has(boss_id), "boss doesn't have an AI"); auto& player_combat = world->get(level.player); - auto& boss_ai = world->get(boss_id); auto& boss_combat = world->get(boss_id); + auto& boss_ai = world->get(boss_id); combat::BattleEngine battle; battle.add_enemy({boss_id, boss_ai, boss_combat}); diff --git a/boss/ui.cpp b/boss/ui.cpp index e39fa36..87adce3 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -3,14 +3,19 @@ #include "constants.hpp" #include "components.hpp" #include "animation.hpp" +#include +#include "game_level.hpp" namespace boss { using namespace guecs; + using namespace DinkyECS; - UI::UI(components::AnimatedScene& scene, Entity boss_id) : + UI::UI(shared_ptr world, Entity boss_id, Entity player_id) : + $world(world), $boss_id(boss_id), + $player_id(player_id), $combat_ui(true), - $arena(scene), + $arena(world->get($boss_id)), $view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}), $view_sprite($view_texture.getTexture()) { @@ -33,7 +38,7 @@ namespace boss { auto stats = $actions.entity("stats"); $actions.set(stats, {}); - $actions.set(stats, {L"stats"}); + update_stats(); $actions.init(); @@ -41,6 +46,14 @@ namespace boss { $combat_ui.init(cell.x, cell.y, cell.w, cell.h); } + void UI::update_stats() { + auto& player_combat = $world->get($player_id); + auto& boss_combat = $world->get($boss_id); + + $actions.show_text("stats", fmt::format( + L"PLAYER: {}\nBOSS: {}", player_combat.hp, boss_combat.hp)); + } + void UI::render(sf::RenderWindow& window) { $actions.render(window); $combat_ui.render(window); diff --git a/boss/ui.hpp b/boss/ui.hpp index 66ecc39..66c343e 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -9,11 +9,18 @@ namespace components { struct Animation; } +// needed to break an include cycle +namespace GameDB { + struct Level; +} + namespace boss { using std::shared_ptr; struct UI { + shared_ptr $world = nullptr; DinkyECS::Entity $boss_id = DinkyECS::NONE; + DinkyECS::Entity $player_id = DinkyECS::NONE; gui::CombatUI $combat_ui; scene::Engine $arena; guecs::UI $actions; @@ -21,7 +28,7 @@ namespace boss { sf::Sprite $view_sprite; cinematic::Camera $camera; - UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id); + UI(shared_ptr world, DinkyECS::Entity boss_id, DinkyECS::Entity player_id); void init(); void render(sf::RenderWindow& window); @@ -29,6 +36,7 @@ namespace boss { void status(const std::wstring& msg); void move_actor(const std::string& actor, const std::string& cell_name); void animate_actor(const std::string& actor); + void update_stats(); void play_animations(); void zoom(const std::string &cell); };