aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sdl/bg-style.c2
-rw-r--r--src/sdl/bg-style.h2
-rw-r--r--src/sdl/draw.c114
3 files changed, 38 insertions, 80 deletions
diff --git a/src/sdl/bg-style.c b/src/sdl/bg-style.c
index 02bc759..7031383 100644
--- a/src/sdl/bg-style.c
+++ b/src/sdl/bg-style.c
@@ -4,7 +4,7 @@
#define M_2_PI (2.0 * 3.1415926)
#define BG_STYLE_GET_CHANNEL(c, time) ((c).base + (((c).period) ? ( \
- (c).amplitude * sin(((c).phase + (time)) * M_2_PI / (1.0 * (c).period)) \
+ (c).scale * sin(((c).phase + (time)) * M_2_PI / (1.0 * (c).period)) \
) : 0))
SDL_Color
diff --git a/src/sdl/bg-style.h b/src/sdl/bg-style.h
index c4ca9a5..6f7903b 100644
--- a/src/sdl/bg-style.h
+++ b/src/sdl/bg-style.h
@@ -6,7 +6,7 @@
typedef struct {
struct {
int base,
- amplitude,
+ scale,
phase,
period;
} r, g, b, a;
diff --git a/src/sdl/draw.c b/src/sdl/draw.c
index 14307b5..5138f8a 100644
--- a/src/sdl/draw.c
+++ b/src/sdl/draw.c
@@ -32,26 +32,6 @@ get_cell_rect(
}
static void
-on_size(
- const sok_ctx_t * const ctx,
- const sok_pos_t level_size,
- void * const data
-) {
- draw_ctx_t * const draw_ctx = data;
- const size_t cell_size = get_cell_size(draw_ctx);
-
- // get renderer size
- int renderer_x, renderer_y;
- if (SDL_GetRendererOutputSize(draw_ctx->renderer, &renderer_x, &renderer_y)) {
- die("SDL_GetRendererOutputSize(): %s", SDL_GetError());
- }
-
- // calculate renderer offset
- draw_ctx->render_ofs_x = (renderer_x - level_size.x * cell_size) / 2;
- draw_ctx->render_ofs_y = (renderer_y - level_size.y * cell_size) / 2;
-}
-
-static void
draw_cell(
draw_ctx_t * const draw_ctx,
const sok_pos_t pos,
@@ -66,27 +46,6 @@ 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
@@ -113,14 +72,25 @@ draw_border(
}
static bool
-draw_sprites_on_size(
+draw_on_size(
const sok_ctx_t * const ctx,
const sok_pos_t level_size,
void * const data
) {
- on_size(ctx, level_size, data);
draw_ctx_t * const draw_ctx = data;
+ const size_t cell_size = get_cell_size(draw_ctx);
+
+ // get renderer size
+ int renderer_x, renderer_y;
+ if (SDL_GetRendererOutputSize(draw_ctx->renderer, &renderer_x, &renderer_y)) {
+ die("SDL_GetRendererOutputSize(): %s", SDL_GetError());
+ }
+
+ // calculate renderer offset
+ draw_ctx->render_ofs_x = (renderer_x - level_size.x * cell_size) / 2;
+ draw_ctx->render_ofs_y = (renderer_y - level_size.y * cell_size) / 2;
+ // draw border
draw_border(draw_ctx, level_size);
// draw floor
@@ -137,7 +107,7 @@ draw_sprites_on_size(
}
static bool
-draw_sprites_on_wall(
+draw_on_wall(
const sok_ctx_t * const ctx,
const sok_pos_t pos,
void * const data
@@ -148,7 +118,7 @@ draw_sprites_on_wall(
}
static bool
-draw_sprites_on_goal(
+draw_on_goal(
const sok_ctx_t * const ctx,
const sok_pos_t pos,
const bool has_player,
@@ -161,19 +131,28 @@ draw_sprites_on_goal(
}
static bool
-draw_sprites_on_home(
+draw_on_home(
const sok_ctx_t * const ctx,
const sok_pos_t pos,
const bool has_goal,
void * const data
) {
draw_ctx_t * const draw_ctx = data;
- draw_home(draw_ctx, pos);
+ 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());
+ }
+
return true;
}
static bool
-draw_sprites_on_box(
+draw_on_box(
const sok_ctx_t * const ctx,
const sok_pos_t pos,
const bool has_goal,
@@ -186,11 +165,11 @@ draw_sprites_on_box(
static const sok_ctx_walk_cbs_t
DRAW_CBS = {
- .on_size = draw_sprites_on_size,
- .on_wall = draw_sprites_on_wall,
- .on_goal = draw_sprites_on_goal,
- .on_home = draw_sprites_on_home,
- .on_box = draw_sprites_on_box,
+ .on_size = draw_on_size,
+ .on_wall = draw_on_wall,
+ .on_goal = draw_on_goal,
+ .on_home = draw_on_home,
+ .on_box = draw_on_box,
};
static const text_style_t
@@ -258,7 +237,6 @@ HELP_STYLE = {
},
};
-
static void
draw_help_text(
draw_ctx_t * const draw_ctx
@@ -286,30 +264,10 @@ BG_STYLES[] = {{
.a = { .base = 0xFF },
}, {
// won style
- .r = {
- .base = 0x66,
- .amplitude = 0x33,
- .phase = 1000,
- .period = 2000,
- },
-
- .g = {
- .base = 0x66,
- .amplitude = 0x33,
- .phase = 3000,
- .period = 5000,
- },
-
- .b = {
- .base = 0x66,
- .amplitude = 0x33,
- .phase = 5000,
- .period = 7000,
- },
-
- .a = {
- .base = 0xFF,
- },
+ .r = { .base = 0x66, .scale = 0x33, .phase = 1000, .period = 2000 },
+ .g = { .base = 0x66, .scale = 0x33, .phase = 3000, .period = 5000 },
+ .b = { .base = 0x66, .scale = 0x33, .phase = 5000, .period = 7000 },
+ .a = { .base = 0xFF },
}};
static void