diff --git a/include/conf.h b/include/conf.h index f0f6077..e47aedc 100644 --- a/include/conf.h +++ b/include/conf.h @@ -19,4 +19,5 @@ #define JUMP_GRACE 10 #define AIR_JUMPS 3 #define BURST_BOOST 0.5 -#define TRANS_SPEED (1.0 / 8.0) +#define V_TRANS_SPD (1.0 / 15.0) +#define H_TRANS_SPD (1.0 / 30.0) diff --git a/include/transition.h b/include/transition.h index d87bb50..5bf0002 100644 --- a/include/transition.h +++ b/include/transition.h @@ -23,5 +23,7 @@ struct Transition transition_init(float speed, color_t color, enum TransitionMode mode); enum TransitionMode transition_update(struct Transition *transition); void transition_draw(struct Transition transition); +void hfade_in(float step, color_t color); +void hfade_out(float step, color_t color); void vfade_in(float step, color_t color); void vfade_out(float step, color_t color); diff --git a/src/level/draw.c b/src/level/draw.c index b371719..659af93 100644 --- a/src/level/draw.c +++ b/src/level/draw.c @@ -22,27 +22,26 @@ void level_draw(void) while (x-- > 0) { const int draw_x = x * TILE_WIDTH; const int tile_index = x + y * level.width; - const Tile tile = - level.data[tile_index]; + const Tile tile = level.data[tile_index]; switch (tile) { case TILE_VOID: break; case TILE_SOLID: { const int autotile = level.autotiling[tile_index]; - dsubimage(draw_x, draw_y, - &bimg_tileset, autotile, - TILE_HEIGHT, TILE_WIDTH, - TILE_HEIGHT, DIMAGE_NOCLIP); + dsubimage(draw_x, draw_y, &bimg_tileset, + autotile, TILE_HEIGHT, + TILE_WIDTH, TILE_HEIGHT, + DIMAGE_NOCLIP); } break; default: - dsubimage(draw_x, draw_y, - &bimg_tileset, - (int)(tile % tileset_width) * - TILE_WIDTH, - (int)(tile / tileset_width) * - TILE_HEIGHT, TILE_WIDTH, - TILE_HEIGHT, DIMAGE_NOCLIP); + dsubimage(draw_x, draw_y, &bimg_tileset, + (int)(tile % tileset_width) * + TILE_WIDTH, + (int)(tile / tileset_width) * + TILE_HEIGHT, + TILE_WIDTH, TILE_HEIGHT, + DIMAGE_NOCLIP); break; } } diff --git a/src/main.c b/src/main.c index c3cb215..b9e905b 100644 --- a/src/main.c +++ b/src/main.c @@ -57,7 +57,7 @@ int main(void) particles_init(); /* initialize transitions */ struct Transition transition = - transition_init(TRANS_SPEED, C_WHITE, TransitionVIn); + transition_init(0.0, C_BLACK, TransitionNone); /* timer setup */ timer = timer_setup(TIMER_ANY, 1000000 / TARGET_UPS, callback, &has_ticked); @@ -84,12 +84,12 @@ int main(void) case 1: level_id += 1; transition = transition_init( - TRANS_SPEED, C_BLUE, - TransitionVOut); + H_TRANS_SPD, C_BLUE, + TransitionHOut); break; case -1: transition = transition_init( - TRANS_SPEED, C_RED, + V_TRANS_SPD, C_RED, TransitionVOut); break; default: @@ -109,12 +109,16 @@ int main(void) case TransitionHIn: break; case TransitionHOut: + transition = transition_init( + transition.speed, + transition.color, + TransitionHIn); break; case TransitionVIn: break; case TransitionVOut: transition = transition_init( - TRANS_SPEED, + transition.speed, transition.color, TransitionVIn); break; diff --git a/src/transition/draw.c b/src/transition/draw.c index 9f9a8e7..a9bff64 100644 --- a/src/transition/draw.c +++ b/src/transition/draw.c @@ -9,8 +9,10 @@ void transition_draw(struct Transition transition) case TransitionNone: break; case TransitionHIn: + hfade_in(transition.step, transition.color); break; case TransitionHOut: + hfade_out(transition.step, transition.color); break; case TransitionVIn: vfade_in(transition.step, transition.color); diff --git a/src/transition/fade.c b/src/transition/fade.c index 5a95a46..0af526d 100644 --- a/src/transition/fade.c +++ b/src/transition/fade.c @@ -4,9 +4,32 @@ #include "transition.h" #include +static float square(float x); +static float isquare(float x); + +void hfade_in(float step, color_t color) +{ + int line = isquare(step) * DWIDTH; + int x; + drect(line, 0, DWIDTH, DHEIGHT, C_BLACK); + for (x = line; x < line + 2; x += 1) { + dvline(x, color); + } +} + +void hfade_out(float step, color_t color) +{ + int line = square(step) * DWIDTH; + int x; + drect(0, 0, line, DHEIGHT, C_BLACK); + for (x = line - 2; x < line; x += 1) { + dvline(x, color); + } +} + void vfade_in(float step, color_t color) { - int line = step * DHEIGHT; + int line = isquare(step) * DHEIGHT; int y; drect(0, line, DWIDTH, DHEIGHT, C_BLACK); for (y = line; y < line + 2; y += 1) { @@ -16,10 +39,14 @@ void vfade_in(float step, color_t color) void vfade_out(float step, color_t color) { - int line = step * DHEIGHT; + int line = square(step) * DHEIGHT; int y; drect(0, 0, DWIDTH, line, C_BLACK); for (y = line - 2; y < line; y += 1) { dhline(y, color); } } + +static float square(float x) { return x * x; } + +static float isquare(float x) { return 1.0 - square(1.0 - x); }