diff --git a/boss/fight.cpp b/boss/fight.cpp index b9f8fe8..4a90888 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -66,7 +66,7 @@ namespace boss { break; case ATTACK: if($battle.player_request("kill_enemy")) { - fmt::println("player requests kill_enemy {} vs. {}", + fmt::println("player requests kill_enemy {} vs. {}", $host_combat->ap, $battle.player_pending_ap()); } else { fmt::println("NO MORE ACTION!"); diff --git a/boss/ui.cpp b/boss/ui.cpp index 9580fc6..9097542 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -110,8 +110,10 @@ namespace boss { if(amount > 0) { $arena.attach_text(target, fmt::format("{}", amount)); $arena.apply_effect(actor, "flame"); - fmt::println("CAMERA zooming by 0.7 to {}", target); - $arena.zoom(target, 0.8f); + + // USING SCALE + float scale = 0.8f; + $arena.zoom(target, scale); } else { $arena.attach_text(actor, "MISSED"); } diff --git a/camera.cpp b/camera.cpp index 0498e87..052e4f7 100644 --- a/camera.cpp +++ b/camera.cpp @@ -29,9 +29,13 @@ namespace cinematic { } Camera::Camera(sf::Vector2f size) : - anim(MGR.animations.at("shake")), + anim(MGR.animations.at("dolly")), + size(size), base_size(size), - size(size) + aimed_at{size.x/2, size.y/2}, + going_to{size.x/2, size.y/2}, + camera_bounds{{0,0}, size}, + view{aimed_at, size} { } @@ -42,10 +46,6 @@ namespace cinematic { {size.x / 2.0f, size.y / 2.0f}, {base_size.x - size.x / 2.0f, base_size.y - size.y / 2.0f} }; - - fmt::println("!!!!! CAMERA BOUNDS camera_bounds={},{},{},{}", - camera_bounds.position.x, camera_bounds.position.y, - camera_bounds.size.x, camera_bounds.size.y); } void Camera::scale(float ratio) { @@ -69,22 +69,12 @@ namespace cinematic { void Camera::position(float x, float y) { aimed_at.x = clamp(x, camera_bounds.position.x, camera_bounds.size.x); aimed_at.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y); - - fmt::println("!!! CAMERA POSITION aimed_at={},{}; x/y={},{}; camera_bounds={},{},{},{}", - aimed_at.x, aimed_at.y, x, y, - camera_bounds.position.x, camera_bounds.position.y, - camera_bounds.size.x, camera_bounds.size.y); } void Camera::move(float x, float y) { going_to.x = clamp(x, camera_bounds.position.x, camera_bounds.size.x); going_to.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y); - fmt::println("!!!! CAMERA MOVE going_to={},{}; x/y={},{}; camera_bounds={},{},{},{}", - going_to.x, going_to.y, x, y, - camera_bounds.position.x, camera_bounds.position.y, - camera_bounds.size.x, camera_bounds.size.y); - // BUG: annoying special case if(anim.motion == ease::SLIDE) { anim.min_x = aimed_at.x; diff --git a/camera.hpp b/camera.hpp index ee4f1e8..c9b6169 100644 --- a/camera.hpp +++ b/camera.hpp @@ -5,12 +5,12 @@ namespace cinematic { struct Camera { components::Animation anim; - sf::View view; - sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT}; - sf::FloatRect camera_bounds{{0,0},{SCREEN_WIDTH, SCREEN_HEIGHT}}; + sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT}; sf::Vector2f aimed_at{0,0}; sf::Vector2f going_to{0,0}; + sf::FloatRect camera_bounds{{0,0},{SCREEN_WIDTH, SCREEN_HEIGHT}}; + sf::View view; Camera(sf::Vector2f base_size); diff --git a/scene.cpp b/scene.cpp index c32422e..f944aaa 100644 --- a/scene.cpp +++ b/scene.cpp @@ -36,8 +36,6 @@ namespace scene { Engine::Engine(components::AnimatedScene& scene) : $scene(scene) { - $camera.style("dolly"); - for(auto& config : $scene.actors) { auto element = config_scene_element(config, false, false); dbc::check(!$actor_name_ids.contains(element.name), @@ -167,16 +165,35 @@ namespace scene { $camera.play(); } + std::pair Engine::left_right(const std::string &actor, const std::string &target) { + auto& first = actor_config(actor); + auto& second = actor_config(target); + + if(first.pos.x < second.pos.x) { + // first is left + return {first, second}; + } else if(first.pos.x == second.pos.x) { + auto fb = first.st.sprite->getGlobalBounds(); + auto sb = second.st.sprite->getGlobalBounds(); + + // use the widest one as right + if(fb.size.x >= sb.size.x) { + return {first, second}; + } else { + return {second, first}; + } + } else { + // second is left + return {second, first}; + } + } + void Engine::zoom(const std::string &actor, float scale) { auto& config = actor_config(actor); auto bounds = config.st.sprite->getGlobalBounds(); float mid_x = config.pos.x + bounds.size.x / 2.0f; float mid_y = config.pos.y + bounds.size.y / 2.0f; - fmt::println("CAMERA in scene::Engine I'm zooming {} by {} @ {},{} size {},{}; going_to mid={},{}", - actor, scale, config.pos.x, config.pos.y, - bounds.size.x, bounds.size.y, mid_x, mid_y); - zoom(mid_x, mid_y, scale); } diff --git a/scene.hpp b/scene.hpp index b36c226..802539b 100644 --- a/scene.hpp +++ b/scene.hpp @@ -54,5 +54,6 @@ namespace scene { void zoom(const std::string& actor, float scale=0.9f); void zoom(float mid_x, float mid_y, float scale); void reset(sf::RenderTexture& view); + std::pair left_right(const std::string &actor, const std::string &target); }; }