Now have the ability to specify parameters needed.

This commit is contained in:
Zed A. Shaw 2025-10-27 23:01:48 -04:00
parent 949bbd4f15
commit c4fcb41c34
3 changed files with 98 additions and 66 deletions

View file

@ -45,37 +45,37 @@ namespace components {
if(stationary) { if(stationary) {
switch(motion) { switch(motion) {
case ease::SHAKE: { case ease::SHAKE: {
pos_out.x += std::lerp(scale_x, max_scale, tick); pos_out.x += std::lerp(min_x, max_x, tick);
} break; } break;
case ease::BOUNCE: { case ease::BOUNCE: {
pos_out.y -= std::lerp(scale_y, max_scale, tick); pos_out.y -= std::lerp(min_y, max_y, tick);
} break; } break;
case ease::RUSH: { case ease::RUSH: {
scale_out.x = std::lerp(scale_x, max_scale, tick); scale_out.x = std::lerp(min_x, max_x, tick);
scale_out.y = std::lerp(scale_y, max_scale, tick); scale_out.y = std::lerp(min_y, max_y, tick);
pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y); pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y);
} break; } break;
case ease::SQUEEZE: { case ease::SQUEEZE: {
scale_out.x *= std::lerp(scale_x, max_scale, tick); scale_out.x *= std::lerp(min_x, max_x, tick);
} break; } break;
case ease::SQUASH: { case ease::SQUASH: {
scale_out.y *= std::lerp(scale_y, max_scale, tick); scale_out.y *= std::lerp(min_y, max_y, tick);
} break; } break;
case ease::STRETCH: { case ease::STRETCH: {
scale_out.x = std::lerp(scale_x, max_scale, tick); scale_out.x = std::lerp(min_x, max_x, tick);
fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}", fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}",
scale_x, max_scale, tick, scale_out.x); min_x, max_x, tick, scale_out.x);
} break; } break;
case ease::GROW: { case ease::GROW: {
scale_out.y = std::lerp(scale_y, max_scale, tick); scale_out.y = std::lerp(min_y, max_y, tick);
} break; } break;
default: default:
dbc::sentinel("Unknown animation.motion setting."); dbc::sentinel("Unknown animation.motion setting.");
} }
} else { } else {
scale_out.x = std::lerp(scale_out.x * scale_x, scale_out.x * max_scale, tick); scale_out.x = std::lerp(scale_out.x * min_x, scale_out.x * max_x, tick);
scale_out.y = std::lerp(scale_out.y * scale_y, scale_out.y * max_scale, tick); scale_out.y = std::lerp(scale_out.y * min_y, scale_out.y * max_y, tick);
} }
if(!simple) { if(!simple) {
@ -93,8 +93,8 @@ namespace components {
rect_out.position.x += current * frame_width; rect_out.position.x += current * frame_width;
} }
} else { } else {
scale_out.x = scale_x; scale_out.x = min_x;
scale_out.y = scale_y; scale_out.y = min_y;
playing = false; playing = false;
current = 0; current = 0;
subframe = 0.0f; subframe = 0.0f;
@ -112,7 +112,7 @@ namespace animation {
bool apply(Animation& anim, sf::Sprite& sprite, sf::Vector2f pos) { bool apply(Animation& anim, sf::Sprite& sprite, sf::Vector2f pos) {
sf::IntRect rect{{0,0}, {anim.frame_width, anim.frame_height}}; sf::IntRect rect{{0,0}, {anim.frame_width, anim.frame_height}};
sf::Vector2f scale{anim.scale_x, anim.scale_y}; sf::Vector2f scale{anim.min_x, anim.min_y};
anim.step(scale, pos, rect); anim.step(scale, pos, rect);
@ -120,7 +120,7 @@ namespace animation {
sprite.setPosition(pos); sprite.setPosition(pos);
// BUG: make this an option: apply_scale, apply_position and ranges for x y // 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) { if(anim.scaled) {
sprite.setScale(scale); sprite.setScale(scale);
} }

View file

@ -4,14 +4,16 @@
"easing": 0, "easing": 0,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 1.0, "max_x": 1.0,
"max_y": 1.0,
"simple": false, "simple": false,
"frames": 5, "frames": 5,
"speed": 0.1, "speed": 0.1,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"scaled": true,
"looped": false "looped": false
}, },
"male_hand": { "male_hand": {
@ -19,12 +21,14 @@
"easing": 0, "easing": 0,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 1.0, "max_x": 1.0,
"max_y": 1.0,
"simple": false, "simple": false,
"frames": 3, "frames": 3,
"speed": 0.08, "speed": 0.08,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -34,12 +38,14 @@
"easing": 0, "easing": 0,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 1.0, "max_x": 1.0,
"max_y": 1.0,
"simple": false, "simple": false,
"frames": 3, "frames": 3,
"speed": 0.08, "speed": 0.08,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -49,12 +55,14 @@
"easing": 0, "easing": 0,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 1.0, "max_x": 1.0,
"max_y": 1.0,
"simple": false, "simple": false,
"frames": 5, "frames": 5,
"speed": 0.5, "speed": 0.5,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -64,9 +72,11 @@
"easing": 0, "easing": 0,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 1.0, "max_x": 1.0,
"max_y": 1.0,
"scaled": true,
"simple": false, "simple": false,
"frames": 3, "frames": 3,
"speed": 0.2, "speed": 0.2,
@ -79,12 +89,14 @@
"easing": 3, "easing": 3,
"motion": 0, "motion": 0,
"ease_rate": 0.2, "ease_rate": 0.2,
"scale_x": 0.5, "min_x": 0.5,
"scale_y": 0.5, "min_y": 0.5,
"max_scale": 0.5, "max_x": 0.5,
"max_y": 0.5,
"simple": true, "simple": true,
"frames": 1, "frames": 1,
"speed": 0.03, "speed": 0.03,
"scaled": true,
"stationary": true, "stationary": true,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -94,12 +106,14 @@
"easing": 1, "easing": 1,
"motion": 0, "motion": 0,
"ease_rate": 0.2, "ease_rate": 0.2,
"scale_x": 1.1, "min_x": 1.1,
"scale_y": 1.1, "min_y": 1.1,
"max_scale": 1.2, "max_x": 1.2,
"max_y": 1.2,
"simple": true, "simple": true,
"frames": 10, "frames": 10,
"speed": 0.3, "speed": 0.3,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -109,12 +123,14 @@
"easing": 1, "easing": 1,
"motion": 0, "motion": 0,
"ease_rate": 0.2, "ease_rate": 0.2,
"scale_x": 1.1, "min_x": 1.1,
"scale_y": 1.1, "min_y": 1.1,
"max_scale": 1.2, "max_x": 1.2,
"max_y": 1.2,
"simple": true, "simple": true,
"frames": 10, "frames": 10,
"speed": 0.3, "speed": 0.3,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -124,12 +140,14 @@
"easing": 3, "easing": 3,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.1, "min_x": 1.1,
"scale_y": 1.1, "min_y": 1.1,
"max_scale": 1.2, "max_x": 1.2,
"max_y": 1.2,
"simple": true, "simple": true,
"frames": 1, "frames": 1,
"speed": 0.6, "speed": 0.6,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -139,12 +157,14 @@
"easing": 3, "easing": 3,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 0.9, "max_x": 0.9,
"max_y": 0.9,
"simple": true, "simple": true,
"frames": 1, "frames": 1,
"speed": 0.5, "speed": 0.5,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": true, "toggled": true,
"looped": false "looped": false
@ -154,12 +174,14 @@
"easing": 2, "easing": 2,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 0.9, "min_x": 0.9,
"scale_y": 0.9, "min_y": 0.9,
"max_scale": 1.1, "max_x": 1.1,
"max_y": 1.1,
"simple": true, "simple": true,
"frames": 10, "frames": 10,
"speed": 1.0, "speed": 1.0,
"scaled": true,
"stationary": false, "stationary": false,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -169,12 +191,14 @@
"easing": 1, "easing": 1,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 0.4, "min_x": 0.4,
"scale_y": 0.4, "min_y": 0.4,
"max_scale": 0.4, "max_x": 0.4,
"max_y": 0.4,
"simple": true, "simple": true,
"frames": 1, "frames": 1,
"speed": 0.02, "speed": 0.02,
"scaled": true,
"stationary": true, "stationary": true,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -184,12 +208,14 @@
"easing": 4, "easing": 4,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 0.6, "min_x": 0.6,
"scale_y": 0.6, "min_y": 0.6,
"max_scale": 2.0, "max_x": 0.8,
"max_y": 0.8,
"simple": false, "simple": false,
"frames": 2, "frames": 2,
"speed": 0.02, "speed": 0.02,
"scaled": true,
"stationary": true, "stationary": true,
"toggled": false, "toggled": false,
"looped": false "looped": false
@ -199,12 +225,14 @@
"easing": 0, "easing": 0,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 0.5, "min_x": 0.5,
"scale_y": 0.5, "min_y": 0.5,
"max_scale": 0.4, "max_x": 0.4,
"max_y": 0.4,
"simple": false, "simple": false,
"frames": 3, "frames": 3,
"speed": 0.2, "speed": 0.2,
"scaled": true,
"stationary": true, "stationary": true,
"toggled": false, "toggled": false,
"looped": true "looped": true
@ -214,12 +242,14 @@
"easing": 2, "easing": 2,
"motion": 0, "motion": 0,
"ease_rate": 0.5, "ease_rate": 0.5,
"scale_x": 1.0, "min_x": 1.0,
"scale_y": 1.0, "min_y": 1.0,
"max_scale": 1.01, "max_x": 1.01,
"max_y": 1.01,
"simple": true, "simple": true,
"frames": 1, "frames": 1,
"speed": 0.01, "speed": 0.01,
"scaled": true,
"stationary": true, "stationary": true,
"toggled": false, "toggled": false,
"looped": false "looped": false

View file

@ -115,15 +115,17 @@ namespace components {
}; };
struct Animation { struct Animation {
float scale_x = 1.0f; float min_x = 1.0f;
float scale_y = 1.0f; float min_y = 1.0f;
float max_scale = 1.0f; float max_x = 1.0f;
float max_y = 1.0f;
bool simple = true; bool simple = true;
int frames = 10; int frames = 1;
float speed = 0.3f; float speed = 0.3f;
ease::Style easing = ease::IN_OUT_BACK; ease::Style easing = ease::IN_OUT_BACK;
ease::Motion motion = ease::RUSH; ease::Motion motion = ease::RUSH;
float ease_rate = 0.5f; float ease_rate = 0.5f;
bool scaled = false;
bool stationary = false; bool stationary = false;
bool toggled = false; bool toggled = false;
bool looped = false; bool looped = false;
@ -161,8 +163,8 @@ namespace components {
ENROLL_COMPONENT(Motion, dx, dy, random); ENROLL_COMPONENT(Motion, dx, dy, random);
ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead);
ENROLL_COMPONENT(Device, config, events); ENROLL_COMPONENT(Device, config, events);
ENROLL_COMPONENT(Animation, scale_x, scale_y, max_scale, simple, frames, ENROLL_COMPONENT(Animation, min_x, min_y, max_x, max_y, simple, frames,
speed, easing, motion, ease_rate, stationary, toggled, looped); speed, easing, motion, ease_rate, scaled, stationary, toggled, looped);
ENROLL_COMPONENT(Sound, attack, death); ENROLL_COMPONENT(Sound, attack, death);
ENROLL_COMPONENT(Collision, has); ENROLL_COMPONENT(Collision, has);