feat: add elapsed time, fix bugs

This commit is contained in:
Martin Prokoph
2025-06-29 18:24:02 +02:00
parent 39c290e22f
commit 7671bdec04
9 changed files with 54 additions and 15 deletions

View File

@@ -15,7 +15,7 @@ public class Tetromino {
public Tetromino(TetrominoShape shape) {
this.shape = shape;
this.collision = shape.boundary;
this.centerPos = Vec2i.of(2, 0);
this.centerPos = Vec2i.of(Tetris.getSpace().getMapWidth()/2-1, -1);
}
public boolean fall() {
@@ -30,8 +30,6 @@ public class Tetromino {
}
Tetris.getSpace().onLinesChanged(this, affectedLines);
Tetris.getSpace().increaseScore(20-fallLength);
if (fallLength >= 1) Tetris.getSpace().spawnTetromino();
else Tetris.stopGame();
return false;
}
fallLength += 1;
@@ -57,7 +55,7 @@ public class Tetromino {
int maxCollisionY = collision.length - 1;
while (collision[maxCollisionY][i] == 0) maxCollisionY--; // Figure out the collision box's bounding
if (newPos.getY()+maxCollisionY >= Tetris.getSpace().getMapHeight() || newPos.getX() + i >= Tetris.getSpace().getMapWidth()) continue;
if (newPos.getY()+maxCollisionY < 0 || newPos.getY()+maxCollisionY >= Tetris.getSpace().getMapHeight() || newPos.getX() + i >= Tetris.getSpace().getMapWidth()) continue;
collides |= Tetris.getSpace().getGameMap()[newPos.getY() + maxCollisionY][newPos.getX() + i] != null;
}
}
@@ -73,7 +71,7 @@ public class Tetromino {
int maxCollisionX = xOffset >= 0 ? collision[i].length - 1 : 0;
while (collision[i][maxCollisionX] == 0) maxCollisionX += xOffset >= 0 ? -1 : 1; // Figure out the collision box's bounding
if (newPos.getY()+maxCollisionX >= Tetris.getSpace().getMapHeight()) continue;
if (newPos.getY()+i < 0 || newPos.getY()+i >= Tetris.getSpace().getMapHeight()) continue;
collides |= Tetris.getSpace().getGameMap()[newPos.getY() + i][newPos.getX() + maxCollisionX] != null;
}
}