Now have a simple camera system that I can configure in json for different motion effects.

This commit is contained in:
Zed A. Shaw 2025-11-03 00:25:48 -05:00
parent 8345097e10
commit 5b57fb2033
11 changed files with 173 additions and 128 deletions

View file

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

View file

@ -12,10 +12,10 @@ namespace boss {
$combat_ui(true),
$arena(scene),
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
$view_sprite($view_texture.getTexture()),
$zoom_anim(animation::load("test_zoom"))
$view_sprite($view_texture.getTexture())
{
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});
$camera.style("bounce");
}
void UI::init() {
@ -45,7 +45,7 @@ namespace boss {
$actions.render(window);
$combat_ui.render(window);
if($zoom_anim.playing) {
if($camera.playing()) {
zoom("player2");
}
@ -80,12 +80,12 @@ namespace boss {
if(cell_name == "") {
sf::View zoom{{BOSS_VIEW_WIDTH/2,BOSS_VIEW_HEIGHT/2}, {BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}};
$view_texture.setView(zoom);
} else if($zoom_anim.playing) {
} else if($camera.playing()) {
auto& cell = $arena.$ui.cell_for(cell_name);
sf::Vector2f pos{float(cell.x/2), float(cell.y/2)};
sf::View zoom;
$zoom_anim.apply(zoom, pos, {BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
$view_texture.setView(zoom);
$camera.resize({BOSS_VIEW_WIDTH/2, BOSS_VIEW_HEIGHT/2});
$camera.move($view_texture,
{float(cell.x/2), float(cell.y/2)});
}
$view_sprite.setPosition({BOSS_VIEW_X, BOSS_VIEW_Y});

View file

@ -3,6 +3,7 @@
#include <guecs/ui.hpp>
#include "gui/combat_ui.hpp"
#include "scene.hpp"
#include "camera.hpp"
namespace components {
struct Animation;
@ -18,7 +19,7 @@ namespace boss {
guecs::UI $actions;
sf::RenderTexture $view_texture;
sf::Sprite $view_sprite;
components::Animation $zoom_anim;
cinematic::Camera $camera;
UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id);