From 9fb117901d67a8cb6f333f096a91a69ce3eb1cc6 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Sun, 9 Mar 2025 21:26:27 +0100 Subject: [PATCH] Start map beating --- game.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/game.h b/game.h index c72d5d1..d66717f 100644 --- a/game.h +++ b/game.h @@ -268,7 +268,6 @@ static inline void LCR_gameDrawPixelXYSafe(unsigned int x, unsigned int y, #define LCR_GUI_GAP \ ((LCR_EFFECTIVE_RESOLUTION_X + LCR_EFFECTIVE_RESOLUTION_Y) / 128) - struct { uint8_t state; @@ -285,6 +284,7 @@ struct frames for which the key has been continuously held. */ uint32_t runTime; ///< Current time of the run, in ticks. + uint8_t mapBeaten; char popupStr[LCR_POPUP_STR_SIZE]; uint8_t popupCountdown; @@ -709,6 +709,44 @@ void LCR_seekDataByIndex(unsigned int index, char magicNumber) } while (c); } +uint8_t LCR_mapIsBeaten(const char *name) +{ + LCR_gameRewindDataFile(); + + while (1) + { + char c = LCR_gameGetNextDataFileChar(); + + if (c == 'B') + { + uint8_t i = 0; + + while (1) + { + c = LCR_gameGetNextDataFileChar(); + + if (name[i] == 0) + { + if (c < ' ' || c == LCR_RESOURCE_FILE_SEPARATOR || + c == LCR_RESOURCE_FILE_SEPARATOR2 || c == 0) + return 1; + else + break; + } + else if (c != name[i]) + break; + + i++; + } + } + + if (c == 0) + break; + } + + return 0; +} + void LCR_gameLoadMap(unsigned int mapIndex) { char mapName[LCR_MAP_NAME_MAX_LEN]; @@ -730,6 +768,7 @@ void LCR_gameLoadMap(unsigned int mapIndex) } LCR_mapLoadFromStr(LCR_gameGetNextDataStrChar,mapName); + LCR_game.mapBeaten = LCR_mapIsBeaten(mapName); } /** @@ -1479,8 +1518,17 @@ uint8_t LCR_gameStep(uint32_t time) LCR_LOG1("finished"); if (LCR_game.runTime <= LCR_currentMap.targetTime) + { LCR_gameSaveReplay(); + if (!LCR_game.mapBeaten && !LCR_game.ghost.active && + !LCR_racing.playingReplay) + { + LCR_LOG1("map beaten"); + // TODO + } + } + LCR_audioPlaySound(LCR_SOUND_CLICK); LCR_gameSetState(LCR_GAME_STATE_RUN_FINISHED); }