hanafuda/move.c

24 lines
712 B
C

#include <math.h>
#include "move.h"
Vector2 move_position(Move *m, float delta) {
m->current_time += delta;
float percentage = m->current_time / m->end_time;
if (percentage < 0.0) percentage = 0.0;
else if (percentage > 1.0) percentage = 1.0;
switch (m->curve) {
case CURVE_LINEAR:
return (Vector2) {
((m->destination.x - m->origin.x) * percentage) + m->origin.x,
((m->destination.y - m->origin.y) * percentage) + m->origin.y
};
case CURVE_EASE_IN_OUT:
percentage = -(cos(PI * percentage) - 1) / 2;
return (Vector2) {
((m->destination.x - m->origin.x) * percentage) + m->origin.x,
((m->destination.y - m->origin.y) * percentage) + m->origin.y
};
}
}