diff --git a/01_text_adventure/intro.c b/01_text_adventure/intro.c index 82f6bbb..6260027 100644 --- a/01_text_adventure/intro.c +++ b/01_text_adventure/intro.c @@ -29,12 +29,26 @@ Intro *load_intro(void) { return i; } +#define SLIDE_TIME 2.0 +#define FADE_IN_TIME 0.5 +#define FADE_OUT_TIME 0.5 void intro_display(Intro *intro) { + float frame_time, elapsed_time, alpha; for (int i = 0; i < intro->texture_count; i++) { - intro->timer = GetTime() + 2.0; - BeginDrawing(); - DrawTexture(intro->textures[i], 0, 0, WHITE); - EndDrawing(); - while(GetTime() < intro->timer) {} + intro->timer = GetTime() + SLIDE_TIME; + while((frame_time = GetTime()) < intro->timer) { + elapsed_time = SLIDE_TIME - (intro->timer - frame_time); + if (elapsed_time < FADE_IN_TIME) + alpha = ((FADE_IN_TIME - elapsed_time) / FADE_IN_TIME) * 255.; + else if (elapsed_time > SLIDE_TIME - FADE_OUT_TIME) + alpha = ((elapsed_time - (SLIDE_TIME - FADE_OUT_TIME)) / FADE_OUT_TIME) * 255.; + else + alpha = 0; + + BeginDrawing(); + DrawTexture(intro->textures[i], 0, 0, WHITE); + DrawRectangle(0, 0, 800, 450, (Color) { 0, 0, 0, alpha }); + EndDrawing(); + } } }