feat(anim): cardinal WEST i flip totalment governat pel motor d'animació

This commit is contained in:
JailDesigner committed 2026-04-29 10:11:27 +02:00
1 parent 9dc7ff0da3
commit 72384c3113
15 files changed
+183 -182

No files matched your search

+24 -13
View File
@@ -26,11 +26,15 @@ namespace {
// Llegeix un bloc d'animació del YAML amb fallbacks tolerants (mateix
// patró que Door/Sarcophagus). Si la clau no apareix, retorna una
// animació d'1 frame loopant, neutra — la momia es podrà moure però
// visualment es quedarà estàtica.
// visualment es quedarà estàtica. Llegeix `flip_h`/`flip_v` (default
// false) i els passa al component perquè el motor sàpiga aplicar-los
// al sprite quan aquesta animació estigui activa.
auto buildAnimation(const fkyaml::node& yaml, const std::string& key) -> AnimationComponent {
std::vector<int> frames = {0};
float fps = 8.0F;
bool loop = true;
bool flip_h = false;
bool flip_v = false;
if (yaml.contains("animations") && yaml["animations"].contains(key)) {
const auto& anim = yaml["animations"][key];
if (anim.contains("frames")) {
@@ -43,8 +47,10 @@ namespace {
}
if (anim.contains("fps")) { fps = anim["fps"].get_value<float>(); }
if (anim.contains("loop")) { loop = anim["loop"].get_value<bool>(); }
if (anim.contains("flip_h")) { flip_h = anim["flip_h"].get_value<bool>(); }
if (anim.contains("flip_v")) { flip_v = anim["flip_v"].get_value<bool>(); }
}
return {frames, fps, loop};
return {frames, fps, loop, flip_h, flip_v};
}
// Busca si el segment [prev, prev+delta] travessa una lane del patró
@@ -75,7 +81,8 @@ namespace {
Mummy::Mummy(const fkyaml::node& yaml)
: anim_walk_south_(buildAnimation(yaml, "walk_south")),
anim_walk_north_(buildAnimation(yaml, "walk_north")),
anim_walk_east_(buildAnimation(yaml, "walk_east")) {
anim_walk_east_(buildAnimation(yaml, "walk_east")),
anim_walk_west_(buildAnimation(yaml, "walk_west")) {
name_ = yaml.contains("name") ? yaml["name"].get_value<std::string>() : std::string("mummy");
collides_ = true;
interactable_ = false;
@@ -125,22 +132,26 @@ Mummy::Mummy(const fkyaml::node& yaml)
void Mummy::changeDirection(float dx, float dy) {
setDirection(dx, dy);
// Prevalença lateral: si hi ha component horitzontal s'usa l'anim
// est + flip segons el signe. Només direccions purament verticals
// disparen walk_north/walk_south. Quan la direcció queda (0,0)
// (cul-de-sac amb NONE) no toquem l'animació: la momia es quedarà al
// frame actual fins que step() li torni a assignar direcció.
if (dx != 0.0F) {
// Una animació per cada cardinal — el flip viu al YAML
// (`walk_west: flip_h: true`) i el codi només selecciona quina
// animació mostrar. Prevalença lateral en diagonals; quan la direcció
// queda (0,0) (cul-de-sac amb NONE) no toquem l'animació: la mòmia es
// quedarà al frame actual fins que step() li torni a assignar direcció.
if (dx > 0.0F) {
anim_ = anim_walk_east_;
flip_ = (dx < 0.0F) ? SDL_FLIP_HORIZONTAL : SDL_FLIP_NONE;
} else if (dx < 0.0F) {
anim_ = anim_walk_west_;
} else if (dy < 0.0F) {
anim_ = anim_walk_north_;
flip_ = SDL_FLIP_NONE;
} else if (dy > 0.0F) {
anim_ = anim_walk_south_;
flip_ = SDL_FLIP_NONE;
}
if (anim_.has_value()) { anim_->reset(); }
if (anim_.has_value()) {
anim_->reset();
// Propaguem el flip que l'animació declara al YAML al camp
// `flip_` que el render llegeix (entity_manager_loadlevel.cpp).
flip_ = anim_->flipMode();
}
}
auto Mummy::chooseDirection(const std::vector<Direction>& allowed) -> Direction {