common_tasks: add common_rotate_velocity
This commit is contained in:
parent
68173e811b
commit
b746738c5c
3 changed files with 22 additions and 12 deletions
|
@ -370,3 +370,14 @@ DEFINE_EXTERN_TASK(common_easing_animate_vec4) {
|
|||
glm_vec4_add(from, d, *ARGS.value);
|
||||
}
|
||||
}
|
||||
|
||||
void common_rotate_velocity(MoveParams *move, real angle, int duration) {
|
||||
cmplx r = cdir(angle / duration);
|
||||
move->retention *= r;
|
||||
WAIT(duration);
|
||||
move->retention /= r;
|
||||
}
|
||||
|
||||
DEFINE_EXTERN_TASK(common_rotate_velocity) {
|
||||
common_rotate_velocity(ARGS.move, ARGS.angle, ARGS.duration);
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ INLINE Rect viewport_bounds(double margin) {
|
|||
}
|
||||
|
||||
cmplx common_wander(cmplx origin, double dist, Rect bounds);
|
||||
void common_rotate_velocity(MoveParams *move, real angle, int duration);
|
||||
|
||||
DECLARE_EXTERN_TASK(
|
||||
common_set_bitflags,
|
||||
|
@ -143,3 +144,12 @@ DECLARE_EXTERN_TASK(
|
|||
glm_ease_t ease;
|
||||
}
|
||||
);
|
||||
|
||||
DECLARE_EXTERN_TASK(
|
||||
common_rotate_velocity,
|
||||
{
|
||||
MoveParams *move;
|
||||
real angle;
|
||||
int duration;
|
||||
}
|
||||
);
|
||||
|
|
|
@ -343,20 +343,9 @@ TASK(aimshot_fairy, { BoxedEnemy e; MoveParams move_enter; MoveParams move_exit;
|
|||
e->move = ARGS.move_exit;
|
||||
}
|
||||
|
||||
TASK(rotate_velocity, {
|
||||
MoveParams *move;
|
||||
real angle;
|
||||
int duration;
|
||||
}) {
|
||||
cmplx r = cdir(ARGS.angle / ARGS.duration);
|
||||
ARGS.move->retention *= r;
|
||||
WAIT(ARGS.duration);
|
||||
ARGS.move->retention /= r;
|
||||
}
|
||||
|
||||
static void set_turning_motion(Enemy *e, cmplx v, real turn_angle, int turn_delay, int turn_duration) {
|
||||
e->move = move_linear(v);
|
||||
INVOKE_SUBTASK_DELAYED(turn_delay, rotate_velocity,
|
||||
INVOKE_SUBTASK_DELAYED(turn_delay, common_rotate_velocity,
|
||||
.move = &e->move,
|
||||
.angle = turn_angle,
|
||||
.duration = turn_duration
|
||||
|
|
Loading…
Reference in a new issue