From d2a9d1132e1cb807fbb3e4132b67945f968ef5b7 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 16 Jan 2019 07:29:17 -0500 Subject: animate hero while solving --- src/sdl/draw.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 322bd7a..762976f 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -137,6 +137,19 @@ draw_on_goal( return true; } +static double +get_home_angle( + const draw_ctx_t * const draw_ctx +) { + if (draw_ctx->state == GAME_STATE_SOLVE) { + return 5 * sin(draw_ctx->ticks * M_2_PI / 2000.0); + } else if (sok_ctx_is_done(draw_ctx->ctx)) { + return 10 * sin(draw_ctx->ticks * M_2_PI / 1000.0); + } else { + return 0; + } +} + static bool draw_on_home( const sok_ctx_t * const ctx, @@ -147,9 +160,8 @@ draw_on_home( UNUSED(ctx); UNUSED(has_goal); draw_ctx_t * const draw_ctx = data; - const double angle = sok_ctx_is_done(draw_ctx->ctx) ? (10 * sin(draw_ctx->ticks * M_2_PI / 1000.0)) : 0; - draw_cell(draw_ctx, pos, SPRITE_HOME, angle); + draw_cell(draw_ctx, pos, SPRITE_HOME, get_home_angle(draw_ctx)); return true; } -- cgit v1.2.3