From a62b3c018d6f86bb1454fe54d9ab6b351b1abf27 Mon Sep 17 00:00:00 2001 From: zulianc Date: Tue, 1 Apr 2025 18:45:01 +0200 Subject: [PATCH] fixed holding spwaning the piece 1 row lower --- src/Core/Game.cpp | 34 ++++++++++--------- src/Core/GameBoard.cpp | 28 ++++++++------- src/Core/GameBoard.h | 3 +- src/Core/Gamemode.h | 2 +- .../AppMenus/GamePiecesAppMenu.cpp | 4 +-- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/Core/Game.cpp b/src/Core/Game.cpp index 648b4b1..963b302 100644 --- a/src/Core/Game.cpp +++ b/src/Core/Game.cpp @@ -67,27 +67,29 @@ void Game::nextFrame(const std::set& playerActions) { if (AREJustEnded) { this->lost = this->board.spawnNextPiece(); this->resetPiece(true); - } - /* IRS and IHS */ - Rotation initialRotation = NONE - + ((this->initialActions.contains(ROTATE_CW)) ? CLOCKWISE : NONE) - + ((this->initialActions.contains(ROTATE_180)) ? DOUBLE : NONE) - + ((this->initialActions.contains(ROTATE_CCW)) ? COUNTERCLOCKWISE : NONE); + /* IRS and IHS */ + bool initialRotated = (this->initialActions.contains(ROTATE_0) || this->initialActions.contains(ROTATE_CW) + || this->initialActions.contains(ROTATE_180) || this->initialActions.contains(ROTATE_CCW)); + Rotation initialRotation = NONE + + ((this->initialActions.contains(ROTATE_CW)) ? CLOCKWISE : NONE) + + ((this->initialActions.contains(ROTATE_180)) ? DOUBLE : NONE) + + ((this->initialActions.contains(ROTATE_CCW)) ? COUNTERCLOCKWISE : NONE); - if (this->initialActions.contains(HOLD)) { - this->lost = (!this->board.hold(initialRotation)); - } - else { - if ((initialRotation != NONE) || this->initialActions.contains(ROTATE_0)) { - this->lost = (!this->board.rotate(initialRotation)); + if (this->initialActions.contains(HOLD)) { + this->board.hold(initialRotation); + } + else { + if (initialRotated) { + this->board.rotate(initialRotation); + } } - } - if (this->lost) { - if (initialRotation == NONE) { + this->lost = this->board.activePieceInWall(); + if (this->lost) { this->board.rotate(NONE); this->lost = this->board.activePieceInWall(); + if (this->lost) { this->framesPassed++; return; @@ -97,7 +99,7 @@ void Game::nextFrame(const std::set& playerActions) { /* HOLD */ if (playerActions.contains(HOLD) && (!this->heldActions.contains(HOLD))) { - if (this->board.hold()) { + if (this->board.hold({})) { this->resetPiece(false); } } diff --git a/src/Core/GameBoard.cpp b/src/Core/GameBoard.cpp index 2459569..75a4ab1 100644 --- a/src/Core/GameBoard.cpp +++ b/src/Core/GameBoard.cpp @@ -11,6 +11,7 @@ #include #include #include +#include GameBoard::GameBoard(int boardWidth, int boardHeight, const std::shared_ptr& piecesList, int nextQueueLength) : @@ -194,12 +195,12 @@ bool GameBoard::activePieceOverlaps(const std::set& safePositions, con return false; } -bool GameBoard::hold(Rotation initialRotation) { +bool GameBoard::hold(std::optional initialRotation) { + Position storedPosition = this->activePiecePosition; std::swap(this->activePiece, this->heldPiece); bool isFirstTimeHolding = (this->activePiece == nullptr); if (isFirstTimeHolding) { - // try with the next piece in queue since there is no piece in the hold box yet if (this->nextQueueLength == 0) { this->activePiece = std::make_shared(this->generator.lookNext()); } @@ -208,21 +209,25 @@ bool GameBoard::hold(Rotation initialRotation) { } } - Piece stored = *this->activePiece; - Position storedPosition = this->activePiecePosition; + // try initial rotation this->goToSpawnPosition(); - this->rotate(initialRotation); + if (initialRotation.has_value()) { + std::shared_ptr storedPiece(this->activePiece); + this->rotate(initialRotation.value()); - // if the piece can't spawn, abort initial rotation + if (this->activePieceInWall()) { + this->activePiece = storedPiece; + } + } + + // if the piece can't spawn, try 0° rotation if (this->activePieceInWall()) { - this->activePiece = std::make_shared(stored); - this->goToSpawnPosition(); + std::shared_ptr storedPiece(this->activePiece); + this->rotate(NONE); // if the piece still can't spawn, abort holding if (this->activePieceInWall()) { - if (isFirstTimeHolding) { - this->activePiece = nullptr; - } + this->activePiece = (isFirstTimeHolding) ? nullptr : storedPiece; std::swap(this->activePiece, this->heldPiece); this->activePiecePosition = storedPosition; return false; @@ -230,7 +235,6 @@ bool GameBoard::hold(Rotation initialRotation) { } if (isFirstTimeHolding) { - // confirm we keep the piece we tried with this->nextQueue.push_back(this->generator.getNext()); this->nextQueue.erase(this->nextQueue.begin()); } diff --git a/src/Core/GameBoard.h b/src/Core/GameBoard.h index 97b1b41..19a0ae3 100644 --- a/src/Core/GameBoard.h +++ b/src/Core/GameBoard.h @@ -7,6 +7,7 @@ #include #include +#include /** @@ -90,7 +91,7 @@ class GameBoard { * Tries holding the active piece or swapping it if one was already stocked, while trying to apply an initial rotation to the newly spawned piece * @return If it suceeded */ - bool hold(Rotation initialRotation = NONE); + bool hold(std::optional initialRotation); /** * Spawns the next piece from the queue diff --git a/src/Core/Gamemode.h b/src/Core/Gamemode.h index 62e60be..22e4cb4 100644 --- a/src/Core/Gamemode.h +++ b/src/Core/Gamemode.h @@ -39,7 +39,7 @@ inline std::string getGamemodeGoal(Gamemode gamemode) { "200 lines", "2 minutes", "200 lines", - "Chill" + "Infinite" }; return GAMEMODE_DESCRIPTIONS[gamemode]; diff --git a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp index ce31b8c..efd8c0c 100644 --- a/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GamePiecesAppMenu.cpp @@ -138,7 +138,7 @@ void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const { xProgress += (1.f + 8.f); } else { - this->placeText(text, {}, "ERROR_UNSUPPORTED", xProgress, yPos, {}); + this->placeText(text, {}, "UNLOADED_" + std::to_string(pieceSize), xProgress, yPos, {}); xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier())); } } @@ -148,7 +148,7 @@ void GamePiecesAppMenu::drawSelectedPiecesRow(float yPos) const { xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier())); } else { - this->placeText(text, {}, "ERROR_UNSUPPORTED", xProgress, yPos, {}); + this->placeText(text, {}, "UNLOADED_" + std::to_string(pieceSize), xProgress, yPos, {}); xProgress += (1.f + (text.getGlobalBounds().size.x / this->settings->getWindowSizeMultiplier())); } }