Now have the ability to specify parameters needed.
This commit is contained in:
parent
949bbd4f15
commit
c4fcb41c34
3 changed files with 98 additions and 66 deletions
|
|
@ -45,37 +45,37 @@ namespace components {
|
|||
if(stationary) {
|
||||
switch(motion) {
|
||||
case ease::SHAKE: {
|
||||
pos_out.x += std::lerp(scale_x, max_scale, tick);
|
||||
pos_out.x += std::lerp(min_x, max_x, tick);
|
||||
} break;
|
||||
case ease::BOUNCE: {
|
||||
pos_out.y -= std::lerp(scale_y, max_scale, tick);
|
||||
pos_out.y -= std::lerp(min_y, max_y, 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);
|
||||
scale_out.x = std::lerp(min_x, max_x, 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);
|
||||
} break;
|
||||
case ease::SQUEEZE: {
|
||||
scale_out.x *= std::lerp(scale_x, max_scale, tick);
|
||||
scale_out.x *= std::lerp(min_x, max_x, tick);
|
||||
|
||||
} break;
|
||||
case ease::SQUASH: {
|
||||
scale_out.y *= std::lerp(scale_y, max_scale, tick);
|
||||
scale_out.y *= std::lerp(min_y, max_y, tick);
|
||||
} break;
|
||||
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: {}",
|
||||
scale_x, max_scale, tick, scale_out.x);
|
||||
min_x, max_x, tick, scale_out.x);
|
||||
} break;
|
||||
case ease::GROW: {
|
||||
scale_out.y = std::lerp(scale_y, max_scale, tick);
|
||||
scale_out.y = std::lerp(min_y, max_y, 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);
|
||||
scale_out.x = std::lerp(scale_out.x * min_x, scale_out.x * max_x, tick);
|
||||
scale_out.y = std::lerp(scale_out.y * min_y, scale_out.y * max_y, tick);
|
||||
}
|
||||
|
||||
if(!simple) {
|
||||
|
|
@ -93,8 +93,8 @@ namespace components {
|
|||
rect_out.position.x += current * frame_width;
|
||||
}
|
||||
} else {
|
||||
scale_out.x = scale_x;
|
||||
scale_out.y = scale_y;
|
||||
scale_out.x = min_x;
|
||||
scale_out.y = min_y;
|
||||
playing = false;
|
||||
current = 0;
|
||||
subframe = 0.0f;
|
||||
|
|
@ -112,7 +112,7 @@ namespace animation {
|
|||
|
||||
bool apply(Animation& anim, sf::Sprite& sprite, sf::Vector2f pos) {
|
||||
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);
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ namespace animation {
|
|||
sprite.setPosition(pos);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@
|
|||
"easing": 0,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 1.0,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.0,
|
||||
"max_y": 1.0,
|
||||
"simple": false,
|
||||
"frames": 5,
|
||||
"speed": 0.1,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"scaled": true,
|
||||
"looped": false
|
||||
},
|
||||
"male_hand": {
|
||||
|
|
@ -19,12 +21,14 @@
|
|||
"easing": 0,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 1.0,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.0,
|
||||
"max_y": 1.0,
|
||||
"simple": false,
|
||||
"frames": 3,
|
||||
"speed": 0.08,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -34,12 +38,14 @@
|
|||
"easing": 0,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 1.0,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.0,
|
||||
"max_y": 1.0,
|
||||
"simple": false,
|
||||
"frames": 3,
|
||||
"speed": 0.08,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -49,12 +55,14 @@
|
|||
"easing": 0,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 1.0,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.0,
|
||||
"max_y": 1.0,
|
||||
"simple": false,
|
||||
"frames": 5,
|
||||
"speed": 0.5,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -64,9 +72,11 @@
|
|||
"easing": 0,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 1.0,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.0,
|
||||
"max_y": 1.0,
|
||||
"scaled": true,
|
||||
"simple": false,
|
||||
"frames": 3,
|
||||
"speed": 0.2,
|
||||
|
|
@ -79,12 +89,14 @@
|
|||
"easing": 3,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.2,
|
||||
"scale_x": 0.5,
|
||||
"scale_y": 0.5,
|
||||
"max_scale": 0.5,
|
||||
"min_x": 0.5,
|
||||
"min_y": 0.5,
|
||||
"max_x": 0.5,
|
||||
"max_y": 0.5,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.03,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -94,12 +106,14 @@
|
|||
"easing": 1,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.2,
|
||||
"scale_x": 1.1,
|
||||
"scale_y": 1.1,
|
||||
"max_scale": 1.2,
|
||||
"min_x": 1.1,
|
||||
"min_y": 1.1,
|
||||
"max_x": 1.2,
|
||||
"max_y": 1.2,
|
||||
"simple": true,
|
||||
"frames": 10,
|
||||
"speed": 0.3,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -109,12 +123,14 @@
|
|||
"easing": 1,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.2,
|
||||
"scale_x": 1.1,
|
||||
"scale_y": 1.1,
|
||||
"max_scale": 1.2,
|
||||
"min_x": 1.1,
|
||||
"min_y": 1.1,
|
||||
"max_x": 1.2,
|
||||
"max_y": 1.2,
|
||||
"simple": true,
|
||||
"frames": 10,
|
||||
"speed": 0.3,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -124,12 +140,14 @@
|
|||
"easing": 3,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.1,
|
||||
"scale_y": 1.1,
|
||||
"max_scale": 1.2,
|
||||
"min_x": 1.1,
|
||||
"min_y": 1.1,
|
||||
"max_x": 1.2,
|
||||
"max_y": 1.2,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.6,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -139,12 +157,14 @@
|
|||
"easing": 3,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 0.9,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 0.9,
|
||||
"max_y": 0.9,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.5,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": true,
|
||||
"looped": false
|
||||
|
|
@ -154,12 +174,14 @@
|
|||
"easing": 2,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 0.9,
|
||||
"scale_y": 0.9,
|
||||
"max_scale": 1.1,
|
||||
"min_x": 0.9,
|
||||
"min_y": 0.9,
|
||||
"max_x": 1.1,
|
||||
"max_y": 1.1,
|
||||
"simple": true,
|
||||
"frames": 10,
|
||||
"speed": 1.0,
|
||||
"scaled": true,
|
||||
"stationary": false,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -169,12 +191,14 @@
|
|||
"easing": 1,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 0.4,
|
||||
"scale_y": 0.4,
|
||||
"max_scale": 0.4,
|
||||
"min_x": 0.4,
|
||||
"min_y": 0.4,
|
||||
"max_x": 0.4,
|
||||
"max_y": 0.4,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.02,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -184,12 +208,14 @@
|
|||
"easing": 4,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 0.6,
|
||||
"scale_y": 0.6,
|
||||
"max_scale": 2.0,
|
||||
"min_x": 0.6,
|
||||
"min_y": 0.6,
|
||||
"max_x": 0.8,
|
||||
"max_y": 0.8,
|
||||
"simple": false,
|
||||
"frames": 2,
|
||||
"speed": 0.02,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
@ -199,12 +225,14 @@
|
|||
"easing": 0,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 0.5,
|
||||
"scale_y": 0.5,
|
||||
"max_scale": 0.4,
|
||||
"min_x": 0.5,
|
||||
"min_y": 0.5,
|
||||
"max_x": 0.4,
|
||||
"max_y": 0.4,
|
||||
"simple": false,
|
||||
"frames": 3,
|
||||
"speed": 0.2,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"looped": true
|
||||
|
|
@ -214,12 +242,14 @@
|
|||
"easing": 2,
|
||||
"motion": 0,
|
||||
"ease_rate": 0.5,
|
||||
"scale_x": 1.0,
|
||||
"scale_y": 1.0,
|
||||
"max_scale": 1.01,
|
||||
"min_x": 1.0,
|
||||
"min_y": 1.0,
|
||||
"max_x": 1.01,
|
||||
"max_y": 1.01,
|
||||
"simple": true,
|
||||
"frames": 1,
|
||||
"speed": 0.01,
|
||||
"scaled": true,
|
||||
"stationary": true,
|
||||
"toggled": false,
|
||||
"looped": false
|
||||
|
|
|
|||
|
|
@ -115,15 +115,17 @@ namespace components {
|
|||
};
|
||||
|
||||
struct Animation {
|
||||
float scale_x = 1.0f;
|
||||
float scale_y = 1.0f;
|
||||
float max_scale = 1.0f;
|
||||
float min_x = 1.0f;
|
||||
float min_y = 1.0f;
|
||||
float max_x = 1.0f;
|
||||
float max_y = 1.0f;
|
||||
bool simple = true;
|
||||
int frames = 10;
|
||||
int frames = 1;
|
||||
float speed = 0.3f;
|
||||
ease::Style easing = ease::IN_OUT_BACK;
|
||||
ease::Motion motion = ease::RUSH;
|
||||
float ease_rate = 0.5f;
|
||||
bool scaled = false;
|
||||
bool stationary = false;
|
||||
bool toggled = false;
|
||||
bool looped = false;
|
||||
|
|
@ -161,8 +163,8 @@ namespace components {
|
|||
ENROLL_COMPONENT(Motion, dx, dy, random);
|
||||
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, motion, ease_rate, 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);
|
||||
ENROLL_COMPONENT(Sound, attack, death);
|
||||
ENROLL_COMPONENT(Collision, has);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue