From 1607dc62ddcdab56203a568740ca1fa2d2dc0722 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 3 May 2024 23:10:29 +0200 Subject: [PATCH] fix wrong wipe behaviour --- game-ctrl/game.c | 64 +++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/game-ctrl/game.c b/game-ctrl/game.c index cc3d209..b22e539 100644 --- a/game-ctrl/game.c +++ b/game-ctrl/game.c @@ -21,17 +21,12 @@ static uint8_t delayFactor(uint8_t level) { return MAX_LEVEL + 1 - level; } -typedef enum { - e_Phase_Game, e_Phase_GameOver -} phase_t; - typedef enum { e_Start, e_NewStone, e_Down, e_DownDelay, e_ClearRows, e_GameOver, e_GameOverFill, e_GameOverWipe, e_GameOverDelay } state_t; void gameExec(void *handle) { - static phase_t phase; static state_t state = e_Start; static uint8_t gameOverDelay; static uint8_t rowIndex; @@ -41,6 +36,8 @@ void gameExec(void *handle) { static uint16_t score; static bool newHighScoreAchieved; + bool wipedLines = false; + // --- engine begin ------------------------------------------------------- switch (state) { // --- phase: game -------------------------------------------------------- @@ -51,7 +48,6 @@ void gameExec(void *handle) { filledLines = 0; score = 0; newHighScoreAchieved = false; - phase = e_Phase_Game; state = e_NewStone; break; @@ -86,6 +82,32 @@ void gameExec(void *handle) { case e_ClearRows: // clear filled lines + for (uint8_t r = 0; r < CANVAS_HEIGHT; r++) { + if (canvasIsRowFilled(r)) { + score += level; + if (score > eepromReadHighScore()) { + newHighScoreAchieved = true; + eepromWriteHighScore(score); + } + displaySetValue(score); + canvasWipeRow(r); + canvasShow(); + wipedLines = true; + filledLines += 1; + } + } + + if (wipedLines) { + soundCtrl(SOUND_PLING); + } + + if (wipedLines && (filledLines > 0) && ((filledLines % 10) == 0)) { + if (level < MAX_LEVEL) { + level += 1; + } + soundCtrl(SOUND_FANFARE); + } + state = e_NewStone; break; @@ -93,7 +115,6 @@ void gameExec(void *handle) { case e_GameOver: soundCtrl(SOUND_GAMEOVER); rowIndex = CANVAS_HEIGHT; - phase = e_Phase_GameOver; state = e_GameOverFill; break; @@ -123,36 +144,7 @@ void gameExec(void *handle) { } // --- engine end --------------------------------------------------------- - bool wipedLines = false; canvasShow(); - if (phase == e_Phase_Game) { - for (uint8_t r = 0; r < CANVAS_HEIGHT; r++) { - if (canvasIsRowFilled(r)) { - score += level; - if (score > eepromReadHighScore()) { - newHighScoreAchieved = true; - eepromWriteHighScore(score); - } - displaySetValue(score); - canvasWipeRow(r); - canvasShow(); - wipedLines = true; - filledLines += 1; - } - } - } - - if (wipedLines) { - soundCtrl(SOUND_PLING); - } - - if (wipedLines && (filledLines > 0) && ((filledLines % 10) == 0)) { - if (level < MAX_LEVEL) { - level += 1; - } - soundCtrl(SOUND_FANFARE); - } - if (isGameActive()) { displaySetValue(score);