Fade in + out in the intro

This commit is contained in:
Bill Rossi 2025-01-25 08:30:24 -05:00
parent 7f039aa4f2
commit 822090b5f5

View File

@ -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;
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();
while(GetTime() < intro->timer) {}
}
}
}