From df812e3dcd0af5ba932264d7ca1e0131a4a43019 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 16 Jan 2019 12:09:25 -0500 Subject: animate failed moves --- src/sdl/draw.c | 4 ++++ src/sdl/draw.h | 2 +- src/sdl/main.c | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 762976f..37d9ba2 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -10,6 +10,8 @@ #define M_2_PI (2.0 * 3.1415926) +#define BUMP_TIME 300 + static size_t get_cell_size( const draw_ctx_t * const draw_ctx @@ -145,6 +147,8 @@ get_home_angle( 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 if ((draw_ctx->ticks - draw_ctx->bump_ticks) < BUMP_TIME) { + return 10 * sin(draw_ctx->ticks * M_2_PI / (BUMP_TIME / 2.0)); } else { return 0; } diff --git a/src/sdl/draw.h b/src/sdl/draw.h index f947a70..919f362 100644 --- a/src/sdl/draw.h +++ b/src/sdl/draw.h @@ -27,7 +27,7 @@ typedef struct { // render offset int render_ofs_x, render_ofs_y; - Uint32 ticks; + Uint32 ticks, bump_ticks; const theme_t * const theme; diff --git a/src/sdl/main.c b/src/sdl/main.c index 82d6682..123b1d7 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -165,6 +165,7 @@ int main(int argc, char *argv[]) { .renderer = renderer, .zoom = &zoom, .theme = theme_get_default(), + .bump_ticks = SDL_GetTicks() - 5000, }; // set level @@ -184,6 +185,7 @@ int main(int argc, char *argv[]) { bool is_fullscreen = false; bool done = false; while (!done) { + const Uint32 ticks = SDL_GetTicks(); SDL_Event ev; // read events @@ -201,12 +203,14 @@ int main(int argc, char *argv[]) { break; case ACTION_MOVE: if (!sok_ctx_move(&ctx, (sok_dir_t) action.data)) { + draw_ctx.bump_ticks = ticks; warn("move %s failed", SOK_DIR_TO_STR((sok_dir_t) action.data)); } break; case ACTION_UNDO: if (!sok_ctx_undo(&ctx)) { + draw_ctx.bump_ticks = ticks; warn("undo failed"); } @@ -219,6 +223,7 @@ int main(int argc, char *argv[]) { // set level set_level(&draw_ctx, &ctx, level_num); } else { + draw_ctx.bump_ticks = ticks; warn("cannot advance to next level"); } -- cgit v1.2.3