From d2441069818c6e8d2a3f0bd139006e9e7d83c9a8 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 22 Nov 2025 14:53:52 -0500 Subject: [PATCH] When there's actions in the arena the camera moves. --- boss/system.cpp | 7 ------- boss/ui.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++------ camera.cpp | 8 ++++++++ camera.hpp | 3 ++- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/boss/system.cpp b/boss/system.cpp index 2c33f50..92606e8 100644 --- a/boss/system.cpp +++ b/boss/system.cpp @@ -14,11 +14,8 @@ namespace boss { void System::initialize_boss_ai(DinkyECS::World& world, DinkyECS::Entity boss_id) { dbc::check(world.has(boss_id), "boss doesn't have an AI EnemyConfig"); - auto& config = world.get(boss_id); - auto ai_start = ai::load_state(config.ai_start_name); - auto ai_goal = ai::load_state(config.ai_goal_name); ai::EntityAI boss_ai(config.ai_script, ai_start, ai_goal); @@ -65,8 +62,6 @@ namespace boss { battle.set_all("in_combat", true); battle.plan(); - battle.dump(); - while(auto act = battle.next()) { auto [enemy, enemy_action] = *act; @@ -78,12 +73,10 @@ namespace boss { auto& the_belt = world->get_the(); dbc::check(the_belt.has(attack_id), "STOP passing invalid attack IDs to the system."); - fmt::println("player did damage"); } if(enemy_action == combat::BattleAction::ATTACK) { result.enemy_did = enemy.combat.attack(player_combat); - fmt::println("enemy did damage"); } // need to replicate this in the boss UI diff --git a/boss/ui.cpp b/boss/ui.cpp index 87adce3..1f3c843 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -20,7 +20,7 @@ namespace boss { $view_sprite($view_texture.getTexture()) { $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); - $camera.style("bounce"); + $camera.style("shake"); } void UI::init() { @@ -50,8 +50,37 @@ namespace boss { 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)); + std::wstring status = fmt::format( + L"PLAYER: {}\nBOSS: {}", player_combat.hp, boss_combat.hp); + + if($world->has_event()) { + auto [evt, entity, data] = $world->recv(); + auto result = std::any_cast(data); + auto& player_is = $arena.$actors.at($arena.$actor_name_ids.at("player")); + auto& boss_is = $arena.$actors.at($arena.$actor_name_ids.at("boss")); + + if(result.player_did > 0) { + status += L"\nYOU HIT!"; + } else { + status += L"\nYOU MISSED!"; + } + + if(result.enemy_did > 0) { + status += L"\nBOSS HIT!"; + } else { + status += L"\nBOSS MISSED!"; + } + + if(result.player_did > 0) { + zoom(boss_is.cell); + } else if(result.enemy_did > 0) { + zoom(player_is.cell); + } else { + zoom(""); + } + } + + $actions.show_text("stats", status); } void UI::render(sf::RenderWindow& window) { @@ -59,6 +88,7 @@ namespace boss { $combat_ui.render(window); $arena.render($view_texture); + $camera.render($view_texture); $view_texture.display(); window.draw($view_sprite); } @@ -86,9 +116,15 @@ namespace boss { } void UI::zoom(const std::string &cell_name) { - auto& cell = $arena.$ui.cell_for(cell_name); + if(cell_name == "") { + dbc::log("!!!!!!!!! you should add this to guecs"); + $camera.reset($view_texture, BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT); + } else { + auto& cell = $arena.$ui.cell_for(cell_name); - $camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2); - $camera.move(float(cell.mid_x), float(cell.mid_y)); + $camera.resize(BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2); + $camera.move(float(cell.mid_x), float(cell.mid_y)); + $camera.play(); + } } } diff --git a/camera.cpp b/camera.cpp index 1d71f4c..dfd0b65 100644 --- a/camera.cpp +++ b/camera.cpp @@ -56,6 +56,14 @@ namespace cinematic { } } + void Camera::reset(sf::RenderTexture& target, float width, float height) { + size = {width, height}; + aimed_at = {width/2, height/2}; + going_to = {width/2, height/2}; + view = {aimed_at, size}; + target.setView(target.getDefaultView()); + } + void Camera::render(sf::RenderTexture& target) { if(anim.playing) { anim.apply(view, going_to, size); diff --git a/camera.hpp b/camera.hpp index 6ce2cbd..a6c894a 100644 --- a/camera.hpp +++ b/camera.hpp @@ -6,7 +6,7 @@ namespace cinematic { struct Camera { components::Animation anim; sf::View view; - sf::Vector2f size{SCREEN_WIDTH, SCREEN_WIDTH}; + sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f aimed_at{0,0}; sf::Vector2f going_to{0,0}; @@ -19,6 +19,7 @@ namespace cinematic { void render(sf::RenderTexture& target); void play(); void style(const std::string &name); + void reset(sf::RenderTexture& target, float width, float height); }; void init();