fixed holding spwaning the piece 1 row lower

This commit is contained in:
2025-04-01 18:45:01 +02:00
parent 46ebb88ef2
commit a62b3c018d
5 changed files with 39 additions and 32 deletions

View File

@@ -67,27 +67,29 @@ void Game::nextFrame(const std::set<Action>& 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<Action>& playerActions) {
/* HOLD */
if (playerActions.contains(HOLD) && (!this->heldActions.contains(HOLD))) {
if (this->board.hold()) {
if (this->board.hold({})) {
this->resetPiece(false);
}
}

View File

@@ -11,6 +11,7 @@
#include <utility>
#include <cstdlib>
#include <iostream>
#include <optional>
GameBoard::GameBoard(int boardWidth, int boardHeight, const std::shared_ptr<PiecesList>& piecesList, int nextQueueLength) :
@@ -194,12 +195,12 @@ bool GameBoard::activePieceOverlaps(const std::set<Position>& safePositions, con
return false;
}
bool GameBoard::hold(Rotation initialRotation) {
bool GameBoard::hold(std::optional<Rotation> 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<Piece>(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<Piece> 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<Piece>(stored);
this->goToSpawnPosition();
std::shared_ptr<Piece> 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());
}

View File

@@ -7,6 +7,7 @@
#include <vector>
#include <memory>
#include <optional>
/**
@@ -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<Rotation> initialRotation);
/**
* Spawns the next piece from the queue

View File

@@ -39,7 +39,7 @@ inline std::string getGamemodeGoal(Gamemode gamemode) {
"200 lines",
"2 minutes",
"200 lines",
"Chill"
"Infinite"
};
return GAMEMODE_DESCRIPTIONS[gamemode];

View File

@@ -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()));
}
}