diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-14 19:33:59 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-14 19:33:59 -0500 |
commit | d75423815e3f81de0e4fbb8a5dc9aa43fd923f9b (patch) | |
tree | d4d804274abbb8ef9151350b1206dfde19adc180 /src | |
parent | 9d3d13cddb52e70a3271888d0271b74155ea8a76 (diff) | |
download | sok-d75423815e3f81de0e4fbb8a5dc9aa43fd923f9b.tar.bz2 sok-d75423815e3f81de0e4fbb8a5dc9aa43fd923f9b.zip |
rotate boxes on win
Diffstat (limited to 'src')
-rw-r--r-- | src/sdl/draw.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/sdl/draw.c b/src/sdl/draw.c index 5138f8a..f27a6be 100644 --- a/src/sdl/draw.c +++ b/src/sdl/draw.c @@ -35,13 +35,14 @@ static void draw_cell( draw_ctx_t * const draw_ctx, const sok_pos_t pos, - const sprite_t sprite + const sprite_t sprite, + const double angle ) { const SDL_Rect rect = get_cell_rect(draw_ctx, pos); SDL_Texture *tex = draw_ctx->sprites[sprite]; - if (SDL_RenderCopy(draw_ctx->renderer, tex, NULL, &rect)) { - die("SDL_RenderCopy(): %s", SDL_GetError()); + if (SDL_RenderCopyEx(draw_ctx->renderer, tex, NULL, &rect, angle, NULL, SDL_FLIP_NONE)) { + die("SDL_RenderCopyEx(): %s", SDL_GetError()); } } @@ -98,7 +99,7 @@ draw_on_size( for (size_t x = 0; x < level_size.x; x++) { if (x > 0 && y > 0 && x < level_size.x - 1 && y < level_size.y - 1) { const sok_pos_t pos = { x, y }; - draw_cell(draw_ctx, pos, SPRITE_FLOOR); + draw_cell(draw_ctx, pos, SPRITE_FLOOR, 0); } } } @@ -113,7 +114,7 @@ draw_on_wall( void * const data ) { draw_ctx_t * const draw_ctx = data; - draw_cell(draw_ctx, pos, SPRITE_WALL); + draw_cell(draw_ctx, pos, SPRITE_WALL, 0); return true; } @@ -126,7 +127,7 @@ draw_on_goal( void * const data ) { draw_ctx_t * const draw_ctx = data; - draw_cell(draw_ctx, pos, SPRITE_GOAL); + draw_cell(draw_ctx, pos, SPRITE_GOAL, 0); return true; } @@ -138,15 +139,11 @@ draw_on_home( void * const data ) { draw_ctx_t * const draw_ctx = data; - const SDL_Rect rect = get_cell_rect(draw_ctx, pos); - SDL_Texture *tex = draw_ctx->sprites[SPRITE_HOME]; const bool is_done = sok_ctx_is_done(draw_ctx->ctx); const Uint32 ticks = SDL_GetTicks(); const double angle = is_done ? (10 * sin(ticks * M_2_PI / 1000.0)) : 0; - if (SDL_RenderCopyEx(draw_ctx->renderer, tex, NULL, &rect, angle, NULL, SDL_FLIP_NONE)) { - die("SDL_RenderCopyEx(): %s", SDL_GetError()); - } + draw_cell(draw_ctx, pos, SPRITE_HOME, angle); return true; } @@ -159,7 +156,12 @@ draw_on_box( void * const data ) { draw_ctx_t * const draw_ctx = data; - draw_cell(draw_ctx, pos, SPRITE_BOX); + const Uint32 ticks = SDL_GetTicks(); + const bool is_done = sok_ctx_is_done(draw_ctx->ctx); + const double angle = is_done ? (5 * sin((100 * (pos.y + pos.x) + ticks) * M_2_PI / 1000.0)) : 0; + + draw_cell(draw_ctx, pos, SPRITE_BOX, angle); + return true; } |