diff --git a/src/game/ending.c b/src/game/ending.c index c5f0365..4ec297f 100644 --- a/src/game/ending.c +++ b/src/game/ending.c @@ -33,6 +33,8 @@ static int endingTimer; void initEnding(void) { + startSectionTransition(); + background[0] = getImageFromAtlas("gfx/ending/ending01.jpg"); background[1] = getImageFromAtlas("gfx/ending/ending02.jpg"); @@ -46,22 +48,33 @@ void initEnding(void) app.delegate.logic = &logic; app.delegate.draw = &draw; + + endSectionTransition(); } static void logic(void) { if (--endingTimer <= -FPS / 2) { - if (++endingTextIndex == 3) - { - endingImageIndex++; - startSectionTransition(); - endSectionTransition(); - } - if (endingTextIndex < NUM_ENDING_LINES) { - endingTimer = strlen(endingText[endingTextIndex]) * 4; + if (++endingTextIndex == 3) + { + endingImageIndex++; + startSectionTransition(); + endSectionTransition(); + } + + if (endingTextIndex < NUM_ENDING_LINES) + { + endingTimer = strlen(endingText[endingTextIndex]) * 4; + } + else + { + fadeMusic(3000); + + endingTimer = FPS * 4; + } } else { @@ -79,7 +92,7 @@ static void draw(void) blitRectScaled(atlasTexture->texture, 0, SCREEN_HEIGHT - h, SCREEN_WIDTH, h, &background[endingImageIndex]->rect, 0); - if (endingTimer > 0) + if (endingTimer > 0 && endingTextIndex < NUM_ENDING_LINES) { limitTextWidth(SCREEN_WIDTH / 2); th = getWrappedTextHeight(endingText[endingTextIndex], 24) + 15; diff --git a/src/game/ending.h b/src/game/ending.h index ff0118c..c43b5e7 100644 --- a/src/game/ending.h +++ b/src/game/ending.h @@ -33,6 +33,7 @@ extern void initCredits(int playMusic); extern void limitTextWidth(int width); extern char *readFile(const char *filename); extern void startSectionTransition(void); +extern void fadeMusic(int ms); extern App app; extern Colors colors; diff --git a/src/hub/postMission.c b/src/hub/postMission.c index 18be5cd..befd33a 100644 --- a/src/hub/postMission.c +++ b/src/hub/postMission.c @@ -77,16 +77,14 @@ void initPostMission(void) if (world.isReturnVisit) { saveGame(); - - saveWorld(); } else { restoreGameState(); - - saveGame(); } + saveGame(); + destroyWorld(); initHub(); diff --git a/src/system/sound.c b/src/system/sound.c index 10670ee..072c280 100644 --- a/src/system/sound.c +++ b/src/system/sound.c @@ -56,6 +56,11 @@ void stopMusic(void) Mix_HaltMusic(); } +void fadeMusic(int ms) +{ + Mix_FadeOutMusic(ms); +} + void musicSetPlaying(int playing) { if (music != NULL)