Better easings and motion but I need better data.

This commit is contained in:
Zed A. Shaw 2025-10-27 22:22:57 -04:00
parent f8158a3ea9
commit 949bbd4f15
10 changed files with 75 additions and 17 deletions

View file

@ -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;
}

View file

@ -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,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Before After
Before After

View file

@ -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<int>(data);
boss::System::combat(attack_id);

View file

@ -1,8 +1,6 @@
#include "boss/ui.hpp"
#include "scene.hpp"
#include "constants.hpp"
#include <chrono>
#include <thread>
namespace boss {
using namespace guecs;

View file

@ -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);

View file

@ -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) {

View file

@ -3,7 +3,6 @@
#include <ranges>
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"];

View file

@ -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