mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-06 21:54:27 -04:00
Update ui_tetris.cpp (#2650)
Start "I" tetromino a bit higher and block rotate if it will cause out of bounds collision.
This commit is contained in:
parent
cfdd1a4c22
commit
7553dafffc
1 changed files with 13 additions and 4 deletions
|
@ -259,8 +259,12 @@ void Tetromino(unsigned char c) {
|
||||||
|
|
||||||
void Initialize(unsigned char c) {
|
void Initialize(unsigned char c) {
|
||||||
colorIndex = c;
|
colorIndex = c;
|
||||||
boardX = 0;
|
|
||||||
boardY = 4;
|
boardY = 4;
|
||||||
|
if (c == 1) { // I-tetromino
|
||||||
|
boardX = -1; // Spawn higher
|
||||||
|
} else {
|
||||||
|
boardX = 0; // Other tetrominos spawn at top
|
||||||
|
}
|
||||||
copyCoordinates(X, Y, c - 1);
|
copyCoordinates(X, Y, c - 1);
|
||||||
rotation_state = 0;
|
rotation_state = 0;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +273,7 @@ void Rotate() {
|
||||||
short newX[4], newY[4];
|
short newX[4], newY[4];
|
||||||
int next_state = (rotation_state + 1) % 4;
|
int next_state = (rotation_state + 1) % 4;
|
||||||
|
|
||||||
if (colorIndex == 2) {
|
if (colorIndex == 2) { // O-tetromino doesn't rotate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,6 +295,7 @@ void Rotate() {
|
||||||
short kickX = kick_tests[rotation_state][test][0];
|
short kickX = kick_tests[rotation_state][test][0];
|
||||||
short kickY = kick_tests[rotation_state][test][1];
|
short kickY = kick_tests[rotation_state][test][1];
|
||||||
|
|
||||||
|
// Calculate new positions
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
short tmpX = X[i] - X[1];
|
short tmpX = X[i] - X[1];
|
||||||
short tmpY = Y[i] - Y[1];
|
short tmpY = Y[i] - Y[1];
|
||||||
|
@ -298,11 +303,13 @@ void Rotate() {
|
||||||
newY[i] = Y[1] + tmpX;
|
newY[i] = Y[1] + tmpX;
|
||||||
int testX = boardX + newX[i] + kickX;
|
int testX = boardX + newX[i] + kickX;
|
||||||
int testY = boardY + newY[i] + kickY;
|
int testY = boardY + newY[i] + kickY;
|
||||||
if (OutOfBounds(testY, testX) || (testX >= 0 && board[testX][testY] != 0)) {
|
// Explicitly block rotations that place blocks above the board
|
||||||
|
if (testX < 0 || OutOfBounds(testY, testX) || (testX >= 0 && board[testX][testY] != 0)) {
|
||||||
goto next_test;
|
goto next_test;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Valid rotation found, apply it
|
||||||
DeleteFigure();
|
DeleteFigure();
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
X[i] = newX[i];
|
X[i] = newX[i];
|
||||||
|
@ -492,7 +499,9 @@ void UpdateBoard() {
|
||||||
|
|
||||||
bool IsOver() {
|
bool IsOver() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
if (board[0][i] != 0) return true;
|
if (board[0][i] != 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue