From 2ecd8528eac75c4e7ca9b637f77193561f30b87d Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 27 Oct 2025 23:54:31 -0400 Subject: [PATCH] Can indicate that a animation is flipped, which will *-1 on the x. --- animation.cpp | 5 ++++- assets/animations.json | 21 +++++++++++++++++++-- assets/bosses.json | 18 ++++++++++++------ boss/fight.cpp | 2 +- components.hpp | 7 +++++-- scene.cpp | 4 +++- scene.hpp | 1 + 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/animation.cpp b/animation.cpp index 1d1a94d..867908e 100644 --- a/animation.cpp +++ b/animation.cpp @@ -99,10 +99,13 @@ namespace components { current = 0; subframe = 0.0f; } + + if(flipped) { + scale_out.x *= -1; + } } } - namespace animation { using namespace components; using namespace textures; diff --git a/assets/animations.json b/assets/animations.json index 2e9922f..a58f480 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -12,7 +12,9 @@ "frames": 5, "speed": 0.1, "stationary": false, + "flipped": false, "toggled": false, + "flipped": false, "scaled": true, "looped": false }, @@ -30,7 +32,9 @@ "speed": 0.08, "scaled": true, "stationary": false, + "flipped": false, "toggled": false, + "flipped": false, "looped": false }, "female_hand": { @@ -48,6 +52,7 @@ "scaled": true, "stationary": false, "toggled": false, + "flipped": false, "looped": false }, "lightning_animation": { @@ -65,6 +70,7 @@ "scaled": true, "stationary": false, "toggled": false, + "flipped": false, "looped": false }, "ritual_crafting_area": { @@ -82,6 +88,7 @@ "speed": 0.2, "stationary": true, "toggled": true, + "flipped": false, "looped": false }, "peasant_girl_rear_view": { @@ -99,6 +106,7 @@ "scaled": true, "stationary": true, "toggled": false, + "flipped": false, "looped": false }, "gold_savior": { @@ -116,6 +124,7 @@ "scaled": true, "stationary": false, "toggled": false, + "flipped": false, "looped": false }, "armored_knight" : { @@ -133,6 +142,7 @@ "scaled": true, "stationary": false, "toggled": false, + "flipped": false, "looped": false }, "axe_ranger": { @@ -150,6 +160,7 @@ "scaled": true, "stationary": false, "toggled": false, + "flipped": false, "looped": false }, "rat_with_sword": { @@ -167,6 +178,7 @@ "scaled": true, "stationary": false, "toggled": true, + "flipped": false, "looped": false }, "hairy_spider": { @@ -184,6 +196,7 @@ "scaled": true, "stationary": false, "toggled": false, + "flipped": false, "looped": false }, "test_boss": { @@ -201,6 +214,7 @@ "scaled": true, "stationary": true, "toggled": false, + "flipped": false, "looped": false }, "rat_king_boss": { @@ -218,6 +232,7 @@ "scaled": true, "stationary": true, "toggled": false, + "flipped": false, "looped": false }, "torch_fixture": { @@ -227,14 +242,15 @@ "ease_rate": 0.5, "min_x": 0.5, "min_y": 0.5, - "max_x": 0.4, - "max_y": 0.4, + "max_x": 0.5, + "max_y": 0.5, "simple": false, "frames": 3, "speed": 0.2, "scaled": true, "stationary": true, "toggled": false, + "flipped": false, "looped": true }, "test_floor": { @@ -252,6 +268,7 @@ "scaled": true, "stationary": true, "toggled": false, + "flipped": false, "looped": false } } diff --git a/assets/bosses.json b/assets/bosses.json index 4428363..b0f3c19 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -20,7 +20,8 @@ "scale_y": 0.6, "x": 0, "y": 0, - "at_mid": false + "at_mid": false, + "flipped": false }, { "name": "player", @@ -30,7 +31,8 @@ "scale_y": 0.5, "x": 0, "y": 0, - "at_mid": false + "at_mid": false, + "flipped": false } ], "fixtures": [ @@ -39,20 +41,24 @@ "sprite": "torch_fixture", "scale_x": 0.5, "scale_y": 0.5, + "flipped": false, "cell": "torch1", "x": 66, "y": -50, - "at_mid": false + "at_mid": false, + "flipped": false }, { "name": "torch_fixture", "sprite": "torch_fixture", - "scale_x": -0.5, + "scale_x": 0.5, "scale_y": 0.5, + "flipped": true, "cell": "torch2", "x": 132, - "y": -30, - "at_mid": false + "y": -50, + "at_mid": false, + "flipped": true } ] }, diff --git a/boss/fight.cpp b/boss/fight.cpp index 38c0113..502fc18 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -105,7 +105,7 @@ namespace boss { break; case ATTACK: { $ui.status(L"BOSS TURN"); - // $ui.move_actor("boss", run % 10 < 5 ? "boss5" : "boss6"); + $ui.move_actor("boss", run % 10 < 5 ? "boss5" : "boss6"); $ui.animate_actor("boss"); int attack_id = std::any_cast(data); boss::System::combat(attack_id); diff --git a/components.hpp b/components.hpp index e2ade3a..fe3500a 100644 --- a/components.hpp +++ b/components.hpp @@ -129,6 +129,7 @@ namespace components { bool stationary = false; bool toggled = false; bool looped = false; + bool flipped = false; int current = 0; bool playing = false; @@ -163,8 +164,10 @@ namespace components { ENROLL_COMPONENT(Motion, dx, dy, random); ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); ENROLL_COMPONENT(Device, config, events); - ENROLL_COMPONENT(Animation, min_x, min_y, max_x, max_y, simple, frames, - speed, easing, motion, ease_rate, scaled, stationary, toggled, looped); + ENROLL_COMPONENT(Animation, min_x, min_y, + max_x, max_y, simple, frames, + speed, easing, motion, ease_rate, + scaled, stationary, toggled, looped, flipped); ENROLL_COMPONENT(Sound, attack, death); ENROLL_COMPONENT(Collision, has); diff --git a/scene.cpp b/scene.cpp index 5143b11..c7c51be 100644 --- a/scene.cpp +++ b/scene.cpp @@ -13,9 +13,11 @@ namespace scene { float scale_y = config["scale_y"]; float x = config["x"]; float y = config["y"]; + bool flipped = config["flipped"]; // BUG: need to make animation optional auto anim = animation::load(sprite_name); + anim.flipped = flipped; if(and_play) anim.play(); std::string cell = config["cell"]; @@ -23,7 +25,7 @@ namespace scene { bool at_mid = config["at_mid"]; - return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid}; + return {name, st, anim, cell, scale_x, scale_y, x, y, at_mid, flipped}; } Engine::Engine(components::AnimatedScene& scene) : diff --git a/scene.hpp b/scene.hpp index 743a7ee..36239cc 100644 --- a/scene.hpp +++ b/scene.hpp @@ -20,6 +20,7 @@ namespace scene { float x = 0; float y = 0; bool at_mid=false; + bool flipped=false; sf::Vector2f pos{0,0}; };