aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-01-14 04:36:00 -0500
committerPaul Duncan <pabs@pablotron.org>2019-01-14 04:36:00 -0500
commitbb9cf9472cad42ad80a53ab4523cabba71978583 (patch)
tree8f4ff6f2071566cc8db36bf2143a3db31dc0549b
parent7ca6a5d76b42f882898c781fe97d28e29a9ec6ac (diff)
downloadsok-bb9cf9472cad42ad80a53ab4523cabba71978583.tar.bz2
sok-bb9cf9472cad42ad80a53ab4523cabba71978583.zip
add win wiggle
-rw-r--r--src/sdl/draw.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/sdl/draw.c b/src/sdl/draw.c
index 09da95e..2dab2ee 100644
--- a/src/sdl/draw.c
+++ b/src/sdl/draw.c
@@ -5,6 +5,8 @@
#include "draw.h"
#include "sprites.h"
+#define M_2_PI (2.0 * 3.1415926)
+
static size_t
get_cell_size(
const draw_ctx_t * const draw_ctx
@@ -62,6 +64,27 @@ draw_cell(
}
static void
+draw_home(
+ draw_ctx_t * const draw_ctx,
+ const sok_pos_t pos
+) {
+ const SDL_Rect rect = get_cell_rect(draw_ctx, pos);
+
+ SDL_Texture *tex = draw_ctx->sprites[SPRITE_HOME];
+ if (sok_ctx_is_done(draw_ctx->ctx)) {
+ const Uint32 ticks = SDL_GetTicks();
+ const double angle = 10 * sin(ticks * M_2_PI / 1000.0);
+ if (SDL_RenderCopyEx(draw_ctx->renderer, tex, NULL, &rect, angle, NULL, SDL_FLIP_NONE)) {
+ die("SDL_RenderCopyEx(): %s", SDL_GetError());
+ }
+ } else {
+ if (SDL_RenderCopy(draw_ctx->renderer, tex, NULL, &rect)) {
+ die("SDL_RenderCopy(): %s", SDL_GetError());
+ }
+ }
+}
+
+static void
draw_border(
draw_ctx_t * const draw_ctx,
const sok_pos_t level_size
@@ -141,7 +164,7 @@ draw_sprites_on_home(
void * const data
) {
draw_ctx_t * const draw_ctx = data;
- draw_cell(draw_ctx, pos, SPRITE_HOME);
+ draw_home(draw_ctx, pos);
return true;
}
@@ -320,9 +343,9 @@ set_bg_won_color(
// gen color
const SDL_Color c = {
- .r = 0x66 + 0x33 * sinf((1000 + ticks) * 2.0 * 3.14159 / 2000.0),
- .g = 0x66 + 0x33 * sinf((3000 + ticks) * 2.0 * 3.14159 / 5000.0),
- .b = 0x66 + 0x33 * sinf((5000 + ticks) * 2.0 * 3.14159 / 7000.0),
+ .r = 0x66 + 0x33 * sinf((1000 + ticks) * M_2_PI / 2000.0),
+ .g = 0x66 + 0x33 * sinf((3000 + ticks) * M_2_PI / 5000.0),
+ .b = 0x66 + 0x33 * sinf((5000 + ticks) * M_2_PI / 7000.0),
.a = 0xFF,
};