From 949bbd4f15909669d66c77434f5684e988b8257f Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Mon, 27 Oct 2025 22:22:57 -0400 Subject: [PATCH] Better easings and motion but I need better data. --- animation.cpp | 46 +++++++++++++++++++--- assets/animations.json | 19 ++++++++- assets/boss2/boss_fight_scene_1_floor.png | Bin 20125 -> 20125 bytes assets/boss2/boss_fight_scene_1_wall.png | Bin 45812 -> 45814 bytes boss/fight.cpp | 2 +- boss/ui.cpp | 2 - components.hpp | 3 +- easings.hpp | 13 +++++- scene.cpp | 3 -- scripts/build_assets.ps1 | 4 +- 10 files changed, 75 insertions(+), 17 deletions(-) diff --git a/animation.cpp b/animation.cpp index 32e7177..8cc6dd4 100644 --- a/animation.cpp +++ b/animation.cpp @@ -1,4 +1,5 @@ #include "animation.hpp" +#include "rand.hpp" namespace components { void Animation::play() { @@ -10,7 +11,7 @@ namespace components { } float Animation::twitching() { - float tick = ease::sine(float(frames) / subframe * ease_rate); + float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate); switch(easing) { case ease::NONE: @@ -23,6 +24,10 @@ namespace components { return ease::sine(ease::out_bounce(tick)); case ease::IN_OUT_BACK: return ease::sine(ease::in_out_back(tick)); + case ease::RANDOM: + return Random::uniform_real(0.0001f, 1.0f); + case ease::NORM_DIST: + return Random::normal(0.5f, 0.1f); default: dbc::sentinel( fmt::format("Invalid easing {} given to animation", @@ -38,9 +43,36 @@ namespace components { float tick = twitching(); if(stationary) { - scale_out.x = std::lerp(scale_x, max_scale, tick); - scale_out.y = std::lerp(scale_y, max_scale, tick); - pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y); + switch(motion) { + case ease::SHAKE: { + pos_out.x += std::lerp(scale_x, max_scale, tick); + } break; + case ease::BOUNCE: { + pos_out.y -= std::lerp(scale_y, max_scale, tick); + } break; + case ease::RUSH: { + scale_out.x = std::lerp(scale_x, max_scale, tick); + scale_out.y = std::lerp(scale_y, max_scale, tick); + pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y); + } break; + case ease::SQUEEZE: { + scale_out.x *= std::lerp(scale_x, max_scale, tick); + + } break; + case ease::SQUASH: { + scale_out.y *= std::lerp(scale_y, max_scale, tick); + } break; + case ease::STRETCH: { + scale_out.x = std::lerp(scale_x, max_scale, tick); + fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}", + scale_x, max_scale, tick, scale_out.x); + } break; + case ease::GROW: { + scale_out.y = std::lerp(scale_y, max_scale, tick); + } break; + default: + dbc::sentinel("Unknown animation.motion setting."); + } } else { scale_out.x = std::lerp(scale_out.x * scale_x, scale_out.x * max_scale, tick); scale_out.y = std::lerp(scale_out.y * scale_y, scale_out.y * max_scale, tick); @@ -86,7 +118,11 @@ namespace animation { sprite.setTextureRect(rect); sprite.setPosition(pos); - sprite.setScale(scale); + + // BUG: make this an option: apply_scale, apply_position and ranges for x y + if(anim.motion != ease::SHAKE && anim.motion != ease::BOUNCE && anim.motion != ease::RUSH) { + sprite.setScale(scale); + } return anim.playing; } diff --git a/assets/animations.json b/assets/animations.json index 439eae3..ddf78c8 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -2,6 +2,7 @@ "burning_animation": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -16,6 +17,7 @@ "male_hand": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -30,6 +32,7 @@ "female_hand": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -44,6 +47,7 @@ "lightning_animation": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -58,6 +62,7 @@ "ritual_crafting_area": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -72,6 +77,7 @@ "peasant_girl_rear_view": { "_type": "Animation", "easing": 3, + "motion": 0, "ease_rate": 0.2, "scale_x": 0.5, "scale_y": 0.5, @@ -86,6 +92,7 @@ "gold_savior": { "_type": "Animation", "easing": 1, + "motion": 0, "ease_rate": 0.2, "scale_x": 1.1, "scale_y": 1.1, @@ -100,6 +107,7 @@ "armored_knight" : { "_type": "Animation", "easing": 1, + "motion": 0, "ease_rate": 0.2, "scale_x": 1.1, "scale_y": 1.1, @@ -114,6 +122,7 @@ "axe_ranger": { "_type": "Animation", "easing": 3, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.1, "scale_y": 1.1, @@ -128,6 +137,7 @@ "rat_with_sword": { "_type": "Animation", "easing": 3, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -142,6 +152,7 @@ "hairy_spider": { "_type": "Animation", "easing": 2, + "motion": 0, "ease_rate": 0.5, "scale_x": 0.9, "scale_y": 0.9, @@ -156,6 +167,7 @@ "test_boss": { "_type": "Animation", "easing": 1, + "motion": 0, "ease_rate": 0.5, "scale_x": 0.4, "scale_y": 0.4, @@ -170,10 +182,11 @@ "rat_king_boss": { "_type": "Animation", "easing": 4, - "ease_rate": 0.9, + "motion": 0, + "ease_rate": 0.5, "scale_x": 0.6, "scale_y": 0.6, - "max_scale": 0.7, + "max_scale": 2.0, "simple": false, "frames": 2, "speed": 0.02, @@ -184,6 +197,7 @@ "torch_fixture": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 0.5, "scale_y": 0.5, @@ -198,6 +212,7 @@ "test_floor": { "_type": "Animation", "easing": 2, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, diff --git a/assets/boss2/boss_fight_scene_1_floor.png b/assets/boss2/boss_fight_scene_1_floor.png index 180007bcff991942c50625472d8aeff539a1546d..f29904aae2189252addc1cf2605cc78e288fc9ed 100644 GIT binary patch delta 75 zcmbO`mvQb~#tp8_98#=ehKJcKwr%!hcJ~rBG7B*b%7 delta 75 zcmbO`mvQb~#tp8_96W-`dQC}Rq&E99yL*Wm8ig2|TN#^LnV4xC7+4t?XtVS>PhROO Pk110lxMt4eyS@hi9o`k9 diff --git a/assets/boss2/boss_fight_scene_1_wall.png b/assets/boss2/boss_fight_scene_1_wall.png index ddb95f2b1e49eb67020f2f5889b5386f0092e34f..73018c8dce14b8661d60e6447fa1e31ac1d320ca 100644 GIT binary patch delta 930 zcmV;T16};|1=)AlB2?s9hwBw2?x;h;mk5JQp-fpm%@yct~s(tQX zYg|g`3RoJ1M-^2o2u}!4trS#~H-+1jbZklZSlFY<1%=EXe^T=O#zRnMX8>Um=rxBBSXpT|KGmq$)UkY^(H^q9}MHA2kJNA zvuqge`-bs(0JeKL%T@F9docVedbz4~?}Bp;PR^@Zd<#z3q2o@CX|Zp~CT>k8;rR%f zqtJQ@j)h9ke)c)Mg~+OW)dg(tK(Cy4E`9-C!Dr$zi+t^~paCNS3>pO%GFlI53;+ND zx|7cX9)DS~;~)(D=M-}Uq17D6W~rL{UtlD_nIx6>kw+B;ZUkzz+Uakt=}!zPnji)W zYgN)_1WXgsrrp?3kc|;R4k>aXfc4_XCqVWI;;Y6!X;v~a;3mW>48It|vj(Gl1C6jf zn0-0Ym+_Z6Z6jTYG8_x0p1d$Hv{h2(eZbYs6@P*oFT3Q-&i8ORHh%7StjXn^GOmO6 z|H2F2j|Xng_^3A?53zS#>1i$bZ{~rQ8&OU4UG)2ARnaaY`y6qL zotk06{DQ$976iEa?U7dIctD4< z@_)T~MsrYoRR`3Cj_zSyu_lYX%D$@+pB6A@lvf_V!qW)n!kcm3OG-qKz~$`93y{`F z3__XTR%Q*O6`1&S=DD_=iP~&`1?}k*10BmIbd2?&>-#AVxr{~m;MuiHD}8(ri_LR8 z=9-V@fM&N#ehQY9z&E@`kEVGaWY62072AGq0*V)K^4zb~cVIbjulM4v!2phV8C8$M)QM3OD z?5GtoHdHV*Ix;dkH83kMFgh?W-PAu|lCmEaGB#8&H99gfIyEpWFfckWFp9w*zmqhw Ez{ujaumAu6 delta 964 zcmV;#13UcoK@Iw~=<`>g_IOVTX$@M1f~cimL;VG{2F*cG6hSoCTGUeVI!^;7@?6e6pZmS{ z9PT|AETNQ=*6Rl#oylr}NuP6Jamm^EiVZt$^w1Jkbagg35u&Dlecn@N##@hBtM<8n ztvMRg6{u?x9#d2;D?BAUvz}E=-VyFllHsWEnXp@v3ku(vdZf%RCMU}LZL$^$_`%XD z>`YW~q>7cKmKK(m<4UJ;%I|&5m)K*O`JlvZ@h)@%Oya}IG~@UgW{^>thwi|;-R^^iXTx~!g~n|t z77XL-$S{h>V10tiOeKHq5Jo;kFH|(w0XR0{{HmfwcHv?RIv>@r7A{FvaZ5Z7Z>P|* z2<O`=vN0maAw^CEuwMN6^iu(H_TUI;NwboX0XHF5Vfcj&uNsW<4K%{` zVD_b@Fa0ld+D5txWjGd0J$YkbXse~n`+=*OD}MwxUUtiwo$ujtZ2a8*Sd+^+Wn2&K zf4~dgj|Xng_^3A?iP$HzsNyXbf(LxYfACL1)ll2|eQS*DgQzC@F8Uo=RkVx9en;G5 zXQvpG5?>UT1{kA?-@Y>}Fqezek0+wCzx|*Spz!T!JGIjDZC1L{J@^sp{plf_(data); boss::System::combat(attack_id); diff --git a/boss/ui.cpp b/boss/ui.cpp index bc4cad0..be0a9f7 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -1,8 +1,6 @@ #include "boss/ui.hpp" #include "scene.hpp" #include "constants.hpp" -#include -#include namespace boss { using namespace guecs; diff --git a/components.hpp b/components.hpp index 774d9ac..a7de9f5 100644 --- a/components.hpp +++ b/components.hpp @@ -122,6 +122,7 @@ namespace components { int frames = 10; float speed = 0.3f; ease::Style easing = ease::IN_OUT_BACK; + ease::Motion motion = ease::RUSH; float ease_rate = 0.5f; bool stationary = false; bool toggled = false; @@ -161,7 +162,7 @@ namespace components { ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); ENROLL_COMPONENT(Device, config, events); ENROLL_COMPONENT(Animation, scale_x, scale_y, max_scale, simple, frames, - speed, easing, ease_rate, stationary, toggled, looped); + speed, easing, motion, ease_rate, stationary, toggled, looped); ENROLL_COMPONENT(Sound, attack, death); ENROLL_COMPONENT(Collision, has); diff --git a/easings.hpp b/easings.hpp index 871d791..8971d81 100644 --- a/easings.hpp +++ b/easings.hpp @@ -9,7 +9,18 @@ namespace ease { OUT_CIRC=2, OUT_BOUNCE=3, IN_OUT_BACK=4, - FUCKFACE + RANDOM=5, + NORM_DIST=6 + }; + + enum Motion { + RUSH=0, + SHAKE=1, + BOUNCE=2, + SQUEEZE=3, + SQUASH=4, + STRETCH=5, + GROW=6 }; inline double sine(double x) { diff --git a/scene.cpp b/scene.cpp index fdd3c81..5143b11 100644 --- a/scene.cpp +++ b/scene.cpp @@ -3,7 +3,6 @@ #include const bool DEBUG=false; -const bool YOU_REMOVED_MID_CELL_IDIOT=false; namespace scene { Element config_scene_element(nlohmann::json& config, bool and_play, bool duped) { @@ -18,8 +17,6 @@ namespace scene { // BUG: need to make animation optional auto anim = animation::load(sprite_name); if(and_play) anim.play(); - anim.scale_x = scale_x; - anim.scale_y = scale_y; std::string cell = config["cell"]; std::string name = config["name"]; diff --git a/scripts/build_assets.ps1 b/scripts/build_assets.ps1 index efa9508..fb87c47 100644 --- a/scripts/build_assets.ps1 +++ b/scripts/build_assets.ps1 @@ -28,9 +28,9 @@ function Build-Images { # Build-Images -Source "Textures" -pixel_count 12 # Build-Images -Source "Sprites" -pixel_count 6 # Build-Images -Source "Items" -pixel_count 2 -Build-Images -Source "Animations" -pixel_count 24 +# Build-Images -Source "Animations" -pixel_count 24 # Build-Images -Source "Hands" -pixel_count 6 -# Build-Images -Source "Boss2" -pixel_count 4 +Build-Images -Source "Boss2" -pixel_count 4 # Build-Images -Source "Fixtures" -pixel_count 24