From b746738c5c97e692d5993f680c674b4f5a42ca1f Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev Date: Sat, 24 Sep 2022 02:22:40 +0200 Subject: [PATCH] common_tasks: add common_rotate_velocity --- src/common_tasks.c | 11 +++++++++++ src/common_tasks.h | 10 ++++++++++ src/stages/stage2/timeline.c | 13 +------------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/common_tasks.c b/src/common_tasks.c index ffcef5e5..896291d3 100644 --- a/src/common_tasks.c +++ b/src/common_tasks.c @@ -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); +} diff --git a/src/common_tasks.h b/src/common_tasks.h index f613b5a5..808158c1 100644 --- a/src/common_tasks.h +++ b/src/common_tasks.h @@ -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; + } +); diff --git a/src/stages/stage2/timeline.c b/src/stages/stage2/timeline.c index ee0a9e56..8aabc467 100644 --- a/src/stages/stage2/timeline.c +++ b/src/stages/stage2/timeline.c @@ -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