diff --git a/constants.h b/constants.h index 63ab62c..2cae5f5 100644 --- a/constants.h +++ b/constants.h @@ -166,6 +166,16 @@ */ #define SFG_STORYTEXT_DURATION 15000 +/** + Time in ms of the player death animation. +*/ +#define SFG_LOSE_ANIMATION_DURATION 2000 + +/** + Time in ms of the level win animation. +*/ +#define SFG_WIN_ANIMATION_DURATION 500 + // ---------------------------- // derived constants diff --git a/main.c b/main.c index 1582260..0ae9af5 100755 --- a/main.c +++ b/main.c @@ -2730,6 +2730,11 @@ void SFG_gameStepPlaying() eliminate = 0; break; + case SFG_LEVEL_ELEMENT_FINISH: + SFG_setGameState(SFG_GAME_STATE_WIN); + eliminate = 0; + break; + default: eliminate = 0; break; @@ -2951,7 +2956,7 @@ void SFG_gameStep() case SFG_GAME_STATE_LOSE: { - // player die animation + // player die animation (lose) SFG_updateLevel(); @@ -2972,6 +2977,20 @@ void SFG_gameStep() break; } + case SFG_GAME_STATE_WIN: + { + // win animation + + SFG_updateLevel(); + + int32_t t = SFG_game.frameTime - SFG_game.stateChangeTime; + + if ((t > SFG_WIN_ANIMATION_DURATION) && SFG_keyIsDown(SFG_KEY_A)) + SFG_setGameState(SFG_GAME_STATE_MENU); + + break; + } + case SFG_GAME_STATE_MAP: if (SFG_keyIsDown(SFG_KEY_B)) SFG_setGameState(SFG_GAME_STATE_MENU); @@ -3371,6 +3390,22 @@ void SFG_drawMenu() #undef SCROLL_PIXELS_PER_FRAME } +void SFG_drawWinOverlay() +{ + uint32_t t = RCL_min(SFG_WIN_ANIMATION_DURATION, + SFG_game.frameTime - SFG_game.stateChangeTime); + + uint32_t l = (t * (SFG_GAME_RESOLUTION_Y / 4)) / SFG_WIN_ANIMATION_DURATION; + + +for (uint16_t j = 0; j < l; ++j) + for (uint16_t i = 0; i < SFG_GAME_RESOLUTION_X; ++i) + { + SFG_setPixel(i,j,0); + SFG_setPixel(i,SFG_GAME_RESOLUTION_Y - j - 1,0); + } +} + void SFG_draw() { #if SFG_BACKGROUND_BLUR != 0 @@ -3627,6 +3662,9 @@ void SFG_draw() <= SFG_HUD_BORDER_INDICATOR_DURATION_FRAMES) SFG_drawIndicationBorder(SFG_HUD_BORDER_INDICATOR_WIDTH_PIXELS, SFG_HUD_ITEM_TAKEN_INDICATION_COLOR); + + if (SFG_game.state == SFG_GAME_STATE_WIN) + SFG_drawWinOverlay(); } } diff --git a/settings.h b/settings.h index 2bf25c3..e04a4bd 100644 --- a/settings.h +++ b/settings.h @@ -177,11 +177,6 @@ */ #define SFG_BACKGROUND_BLUR 0 -/** - Time in ms of the player death animation. -*/ -#define SFG_LOSE_ANIMATION_DURATION 2000 - //------ developer/debug settings ------ /**