BAD: This gets the animation to control the camera, but it's a quick hack to prove it works.

This commit is contained in:
Zed A. Shaw 2025-11-01 01:15:18 -04:00
parent cb58bdd955
commit 102c8c36d5
5 changed files with 63 additions and 18 deletions

View file

@ -36,8 +36,8 @@ namespace components {
} }
void Animation::step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out) { void Animation::step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out) {
dbc::check(rect_out.size.x > 0, "invalid frame width in animation"); dbc::check(rect_out.size.x > 0, "step given rect_out with size.x <= 0, must be >");
dbc::check(rect_out.size.y > 0, "invalid frame height in animation"); dbc::check(rect_out.size.y > 0, "step given rect_out with size.y <= 0, must be >");
if(playing && current < frames) { if(playing && current < frames) {
float tick = twitching(); float tick = twitching();
@ -64,8 +64,6 @@ namespace components {
} break; } break;
case ease::STRETCH: { case ease::STRETCH: {
scale_out.x = std::lerp(min_x, max_x, tick); scale_out.x = std::lerp(min_x, max_x, tick);
fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}",
min_x, max_x, tick, scale_out.x);
} break; } break;
case ease::GROW: { case ease::GROW: {
scale_out.y = std::lerp(min_y, max_y, tick); scale_out.y = std::lerp(min_y, max_y, tick);
@ -151,17 +149,18 @@ namespace animation {
try { try {
auto anim = components::convert<Animation>(data); auto anim = components::convert<Animation>(data);
dbc::check(sprites.contains(name), if(!sprites.contains(name)) {
fmt::format("animation '{}' doesn't have sprite, spelled wrong in config.json?", name)); fmt::println("animation '{}' doesn't have sprite, spelled wrong in config.json?", name);
} else {
auto& sprite_config = sprites[name];
auto& sprite_config = sprites[name]; anim.frame_width = sprite_config["frame_width"];
anim.frame_height = sprite_config["frame_height"];
anim.frame_width = sprite_config["frame_width"]; dbc::check(anim.frame_width > 0 && anim.frame_height > 0,
anim.frame_height = sprite_config["frame_height"]; fmt::format("invalid frame width/height for animation: {}",
name));
dbc::check(anim.frame_width > 0 && anim.frame_height > 0, }
fmt::format("invalid frame width/height for animation: {}",
name));
MGR.animations.insert_or_assign(name, anim); MGR.animations.insert_or_assign(name, anim);
} catch(...) { } catch(...) {

View file

@ -288,5 +288,23 @@
"toggled": false, "toggled": false,
"flipped": false, "flipped": false,
"looped": false "looped": false
},
"test_zoom": {
"_type": "Animation",
"easing": 6,
"motion": 5,
"ease_rate": 0.5,
"min_x": 1.0,
"min_y": 1.0,
"max_x": 1.2,
"max_y": 1.2,
"simple": true,
"frames": 1,
"speed": 0.01,
"scaled": true,
"stationary": true,
"toggled": false,
"flipped": false,
"looped": false
} }
} }

View file

@ -86,7 +86,7 @@ namespace boss {
$ui.status(L"PLAYER TURN"); $ui.status(L"PLAYER TURN");
const std::string& player_pos = run % 10 < 5 ? "player1" : "player2"; const std::string& player_pos = run % 10 < 5 ? "player1" : "player2";
$ui.move_actor("player", player_pos); $ui.move_actor("player", player_pos);
$ui.zoom(player_pos); $ui.$zoom_anim.play();
int attack_id = std::any_cast<int>(data); int attack_id = std::any_cast<int>(data);
boss::System::combat(attack_id); boss::System::combat(attack_id);
state(State::PLAYER_TURN); state(State::PLAYER_TURN);

View file

@ -1,6 +1,8 @@
#include "boss/ui.hpp" #include "boss/ui.hpp"
#include "scene.hpp" #include "scene.hpp"
#include "constants.hpp" #include "constants.hpp"
#include "components.hpp"
#include "animation.hpp"
namespace boss { namespace boss {
using namespace guecs; using namespace guecs;
@ -10,7 +12,8 @@ namespace boss {
$combat_ui(true), $combat_ui(true),
$arena(scene), $arena(scene),
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}), $view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
$view_sprite($view_texture.getTexture()) $view_sprite($view_texture.getTexture()),
$zoom_anim(animation::load("test_zoom"))
{ {
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y}); $view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
} }
@ -40,6 +43,11 @@ namespace boss {
void UI::render(sf::RenderWindow& window) { void UI::render(sf::RenderWindow& window) {
$actions.render(window); $actions.render(window);
$combat_ui.render(window); $combat_ui.render(window);
if($zoom_anim.playing) {
zoom("player2");
}
$arena.render($view_texture); $arena.render($view_texture);
$view_texture.display(); $view_texture.display();
window.draw($view_sprite); window.draw($view_sprite);
@ -71,10 +79,25 @@ namespace boss {
if(cell_name == "") { if(cell_name == "") {
sf::View zoom{{BOSS_VIEW_WIDTH/2,BOSS_VIEW_HEIGHT/2}, {BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}}; sf::View zoom{{BOSS_VIEW_WIDTH/2,BOSS_VIEW_HEIGHT/2}, {BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}};
$view_texture.setView(zoom); $view_texture.setView(zoom);
} else { } else if($zoom_anim.playing) {
auto& cell = $arena.$ui.cell_for(cell_name); auto& cell = $arena.$ui.cell_for(cell_name);
sf::View zoom{{(float)cell.mid_x, (float)cell.mid_y}, sf::Vector2f scale{$zoom_anim.min_x, $zoom_anim.min_y};
{(float)cell.w*3, (float)cell.h*3}}; sf::Vector2f pos{float(cell.x), float(cell.y)};
sf::IntRect rect{{0,0}, {cell.w, cell.h}};
$zoom_anim.step(scale, pos, rect);
fmt::println("SCALE: {},{}; pos: {},{}; rect: {},{};{},{}",
scale.x, scale.y, pos.x, pos.y,
rect.position.x, rect.position.y,
rect.size.x, rect.size.y);
sf::View zoom{pos,
{float(cell.w * 2), float(cell.h * 2)}};
if($zoom_anim.scaled) {
zoom.zoom(scale.x);
}
$view_texture.setView(zoom); $view_texture.setView(zoom);
} }

View file

@ -4,6 +4,10 @@
#include "gui/combat_ui.hpp" #include "gui/combat_ui.hpp"
#include "scene.hpp" #include "scene.hpp"
namespace components {
struct Animation;
}
namespace boss { namespace boss {
using std::shared_ptr; using std::shared_ptr;
@ -14,6 +18,7 @@ namespace boss {
guecs::UI $actions; guecs::UI $actions;
sf::RenderTexture $view_texture; sf::RenderTexture $view_texture;
sf::Sprite $view_sprite; sf::Sprite $view_sprite;
components::Animation $zoom_anim;
UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id); UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id);