Arena is now using the new animate2 but needs to be fixed.

This commit is contained in:
Zed A. Shaw 2026-02-11 13:57:19 -05:00
parent 547e8ec993
commit aaf5aa4165
4 changed files with 82 additions and 16 deletions

View file

@ -61,5 +61,73 @@
"attack": [[0, "Sword_Hit_1"], [1, "Marmot_Scream_1"]], "attack": [[0, "Sword_Hit_1"], [1, "Marmot_Scream_1"]],
"hurt": [[1, "Marmot_Scream_1"]] "hurt": [[1, "Marmot_Scream_1"]]
} }
},
"peasant_girl_rear_view": {
"sheet": {
"frames": 1,
"frame_width": 400,
"frame_height": 540
},
"sequences": {
"idle": {"frames": [0], "durations": [800] },
"hurt": {"frames": [0], "durations": [800] },
"attack": {"frames": [0], "durations": [800] }
},
"transforms": {
"breathe": {
"min_x": 0,
"min_y": 0,
"max_x": 0,
"max_y": -10,
"flipped": false,
"ease_rate": 3.0,
"scaled": false,
"toggled": false,
"looped": true,
"easing": "sine",
"motion": "move_bounce"
}
},
"forms": {
"idle": ["idle", "breathe"],
"attack": ["attack", "breathe"],
"hurt": ["hurt", "breathe"]
},
"sounds": {
"idle": [],
"attack": [],
"hurt": []
}
},
"torch_fixture": {
"sheet": {
"frames": 3,
"frame_width": 256,
"frame_height": 256
},
"sequences": {
"idle": {"frames": [0,1,2], "durations": [100, 100, 100] }
},
"transforms": {
"render": {
"min_x": 0,
"min_y": 0,
"max_x": 0,
"max_y": 0,
"flipped": false,
"ease_rate": 3.0,
"scaled": false,
"toggled": false,
"looped": true,
"easing": "sine",
"motion": "move_none"
}
},
"forms": {
"idle": ["idle", "render"]
},
"sounds": {
"idle": []
}
} }
} }

View file

@ -106,6 +106,7 @@ namespace ease2 {
{"in_out_back", in_out_back}, {"in_out_back", in_out_back},
{"random", random}, {"random", random},
{"normal_dist", normal_dist}, {"normal_dist", normal_dist},
{"none", none},
}; };
std::unordered_map<std::string, MotionFunc> map_of_motions{ std::unordered_map<std::string, MotionFunc> map_of_motions{

View file

@ -1,5 +1,5 @@
#include "scene.hpp" #include "scene.hpp"
#include "animation.hpp" #include "animate2.hpp"
#include <ranges> #include <ranges>
#include "shaders.hpp" #include "shaders.hpp"
#include <fmt/core.h> #include <fmt/core.h>
@ -19,8 +19,8 @@ namespace scene {
bool flipped = config["flipped"]; bool flipped = config["flipped"];
// BUG: need to make animation optional // BUG: need to make animation optional
auto anim = animation::load(sprite_name); auto anim = animate2::load("./assets/animate2.json", sprite_name);
anim.flipped = flipped; anim.transform.flipped = flipped;
if(and_play) anim.play(); if(and_play) anim.play();
std::string cell = config["cell"]; std::string cell = config["cell"];
@ -127,7 +127,7 @@ namespace scene {
void Engine::play_animations() { void Engine::play_animations() {
for(auto& fixture : $fixtures) { for(auto& fixture : $fixtures) {
if(fixture.anim.playing) { if(fixture.anim.playing) {
fixture.anim.apply(*fixture.st.sprite, fixture.pos); fixture.anim.apply(*fixture.st.sprite);
} else { } else {
fixture.effect = nullptr; fixture.effect = nullptr;
} }
@ -135,13 +135,9 @@ namespace scene {
for(auto& actor : $actors) { for(auto& actor : $actors) {
if(actor.anim.playing) { if(actor.anim.playing) {
actor.anim.apply(*actor.st.sprite, actor.pos); actor.anim.apply(*actor.st.sprite);
actor.anim.apply(actor.text, actor.pos); // REFACTOR: actor.anim.apply(actor.text, actor.pos);
if(actor.effect) { if(actor.effect != nullptr) actor.anim.apply_effect(actor.effect);
actor.effect->setUniform("u_time", $clock.getElapsedTime().asSeconds());
sf::Vector2f u_resolution{float(actor.anim.frame_width), float(actor.anim.frame_height)};
actor.effect->setUniform("u_resolution", u_resolution);
}
} else { } else {
actor.effect = nullptr; actor.effect = nullptr;
} }
@ -177,9 +173,10 @@ namespace scene {
} }
void Engine::set_end_cb(std::function<void()> cb) { void Engine::set_end_cb(std::function<void()> cb) {
for(auto& actor : $actors) { // REFACTOR:
actor.anim.end_cb = cb; // for(auto& actor : $actors) {
} // actor.anim.end_cb = cb;
// }
} }
void Engine::reset(sf::RenderTexture& view) { void Engine::reset(sf::RenderTexture& view) {

View file

@ -2,12 +2,12 @@
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include "components.hpp"
#include "textures.hpp" #include "textures.hpp"
#include <SFML/Graphics/RenderWindow.hpp> #include <SFML/Graphics/RenderWindow.hpp>
#include <guecs/ui.hpp> #include <guecs/ui.hpp>
#include "camera.hpp" #include "camera.hpp"
#include <functional> #include <functional>
#include "animate2.hpp"
namespace scene { namespace scene {
using std::shared_ptr; using std::shared_ptr;
@ -16,7 +16,7 @@ namespace scene {
struct Element { struct Element {
std::string name; std::string name;
textures::SpriteTexture st; textures::SpriteTexture st;
components::Animation anim; animate2::Animate2 anim;
std::string cell; std::string cell;
float scale_x = 1.0f; float scale_x = 1.0f;
float scale_y = 1.0f; float scale_y = 1.0f;