Add scoring for soft and hard drops, remove automatic falling points

This commit is contained in:
cmclark00 2025-03-28 14:35:20 -04:00
parent 9ab9b53407
commit 7614cef7e5
2 changed files with 35 additions and 3 deletions

View file

@ -251,8 +251,8 @@ class GameView @JvmOverloads constructor(
return return
} }
// Move the current tetromino down automatically // Update the game state
gameBoard.moveDown() gameBoard.update()
// Update UI with current game state // Update UI with current game state
onGameStateChanged?.invoke(gameBoard.score, gameBoard.level, gameBoard.lines) onGameStateChanged?.invoke(gameBoard.score, gameBoard.level, gameBoard.lines)
@ -653,7 +653,7 @@ class GameView @JvmOverloads constructor(
} }
Direction.VERTICAL -> { Direction.VERTICAL -> {
if (deltaY > blockSize * minMovementThreshold) { if (deltaY > blockSize * minMovementThreshold) {
gameBoard.moveDown() gameBoard.softDrop()
lastTouchY = event.y lastTouchY = event.y
if (currentTime - lastMoveTime >= moveCooldown) { if (currentTime - lastMoveTime >= moveCooldown) {
gameHaptics?.vibrateForPieceMove() gameHaptics?.vibrateForPieceMove()

View file

@ -38,6 +38,7 @@ class GameBoard(
var isGameOver = false var isGameOver = false
var isHardDropInProgress = false // Make public var isHardDropInProgress = false // Make public
var isPieceLocking = false // Make public var isPieceLocking = false // Make public
private var isPlayerSoftDrop = false // Track if the drop is player-initiated
// Scoring state // Scoring state
private var combo = 0 private var combo = 0
@ -165,6 +166,10 @@ class GameBoard(
return if (canMove(0, 1)) { return if (canMove(0, 1)) {
currentPiece?.y = currentPiece?.y?.plus(1) ?: 0 currentPiece?.y = currentPiece?.y?.plus(1) ?: 0
// Only add soft drop points if it's a player-initiated drop
if (isPlayerSoftDrop) {
score += 1
}
onPieceMove?.invoke() onPieceMove?.invoke()
true true
} else { } else {
@ -173,6 +178,15 @@ class GameBoard(
} }
} }
/**
* Player-initiated soft drop
*/
fun softDrop() {
isPlayerSoftDrop = true
moveDown()
isPlayerSoftDrop = false
}
/** /**
* Hard drop the current piece * Hard drop the current piece
*/ */
@ -182,12 +196,21 @@ class GameBoard(
isHardDropInProgress = true isHardDropInProgress = true
val piece = currentPiece ?: return val piece = currentPiece ?: return
// Count how many cells the piece will drop
var dropDistance = 0
while (canMove(0, dropDistance + 1)) {
dropDistance++
}
// Move piece down until it can't move anymore // Move piece down until it can't move anymore
while (canMove(0, 1)) { while (canMove(0, 1)) {
piece.y++ piece.y++
onPieceMove?.invoke() onPieceMove?.invoke()
} }
// Add hard drop points (2 points per cell)
score += dropDistance * 2
// Lock the piece immediately // Lock the piece immediately
lockPiece() lockPiece()
} }
@ -604,4 +627,13 @@ class GameBoard(
private fun getLastClearedLines(): List<Int> { private fun getLastClearedLines(): List<Int> {
return lastClearedLines.toList() return lastClearedLines.toList()
} }
/**
* Update the game state (called by game loop)
*/
fun update() {
if (!isGameOver) {
moveDown()
}
}
} }