Add combo system that tracks consecutive line clears with next piece

This commit is contained in:
cmclark00 2025-03-27 08:51:10 -04:00
parent 2c7639a861
commit 44c4c73feb
4 changed files with 54 additions and 8 deletions

View file

@ -203,6 +203,7 @@ class MainActivity : AppCompatActivity() {
binding.scoreText.text = score.toString() binding.scoreText.text = score.toString()
binding.currentLevelText.text = level.toString() binding.currentLevelText.text = level.toString()
binding.linesText.text = lines.toString() binding.linesText.text = lines.toString()
binding.comboText.text = gameBoard.getCombo().toString()
// Force redraw of next piece preview // Force redraw of next piece preview
binding.nextPieceView.invalidate() binding.nextPieceView.invalidate()

View file

@ -10,6 +10,8 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import java.util.Random import java.util.Random
import android.util.Log import android.util.Log
import com.mintris.model.HighScoreManager
import com.mintris.model.HighScore
class TitleScreen @JvmOverloads constructor( class TitleScreen @JvmOverloads constructor(
context: Context, context: Context,
@ -21,6 +23,7 @@ class TitleScreen @JvmOverloads constructor(
private val glowPaint = Paint() private val glowPaint = Paint()
private val titlePaint = Paint() private val titlePaint = Paint()
private val promptPaint = Paint() private val promptPaint = Paint()
private val highScorePaint = Paint()
private val cellSize = 30f private val cellSize = 30f
private val random = Random() private val random = Random()
private var width = 0 private var width = 0
@ -108,6 +111,16 @@ class TitleScreen @JvmOverloads constructor(
alpha = 180 alpha = 180
} }
// High scores text settings
highScorePaint.apply {
color = Color.WHITE
textSize = 35f
textAlign = Paint.Align.CENTER
typeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)
isAntiAlias = true
alpha = 200
}
// General paint settings for tetrominos (white) // General paint settings for tetrominos (white)
paint.apply { paint.apply {
color = Color.WHITE color = Color.WHITE
@ -239,8 +252,19 @@ class TitleScreen @JvmOverloads constructor(
val titleY = height * 0.4f val titleY = height * 0.4f
canvas.drawText("mintris", width / 2f, titleY, titlePaint) canvas.drawText("mintris", width / 2f, titleY, titlePaint)
// Draw high scores
val highScoreManager = HighScoreManager(context)
val highScores: List<HighScore> = highScoreManager.getHighScores()
val highScoreY = height * 0.5f
if (highScores.isNotEmpty()) {
highScores.forEachIndexed { index: Int, score: HighScore ->
val y = highScoreY + (index * 35f)
canvas.drawText("${index + 1}. ${score.name}: ${score.score}", width / 2f, y, highScorePaint)
}
}
// Draw "touch to start" prompt // Draw "touch to start" prompt
canvas.drawText("touch to start", width / 2f, height * 0.6f, promptPaint) canvas.drawText("touch to start", width / 2f, height * 0.7f, promptPaint)
// Request another frame // Request another frame
invalidate() invalidate()

View file

@ -37,6 +37,7 @@ class GameBoard(
private var lastClearWasTetris = false private var lastClearWasTetris = false
private var lastClearWasPerfect = false private var lastClearWasPerfect = false
private var lastClearWasAllClear = false private var lastClearWasAllClear = false
private var lastPieceClearedLines = false // Track if the last piece placed cleared lines
// Animation state // Animation state
var linesToClear = mutableListOf<Int>() var linesToClear = mutableListOf<Int>()
@ -326,6 +327,18 @@ class GameBoard(
calculateScore(shiftAmount) calculateScore(shiftAmount)
}.start() }.start()
} }
// Update combo based on whether this piece cleared lines
if (shiftAmount > 0) {
if (lastPieceClearedLines) {
combo++
} else {
combo = 1 // Start new combo
}
} else {
combo = 0 // Reset combo if no lines cleared
}
lastPieceClearedLines = shiftAmount > 0
} }
/** /**
@ -397,13 +410,6 @@ class GameBoard(
score += finalScore score += finalScore
}.start() }.start()
// Update combo counter
if (clearedLines > 0) {
combo++
} else {
combo = 0
}
// Update line clear state // Update line clear state
lastClearWasTetris = clearedLines == 4 lastClearWasTetris = clearedLines == 4
lastClearWasPerfect = isPerfectClear lastClearWasPerfect = isPerfectClear
@ -528,6 +534,7 @@ class GameBoard(
lastClearWasTetris = false lastClearWasTetris = false
lastClearWasPerfect = false lastClearWasPerfect = false
lastClearWasAllClear = false lastClearWasAllClear = false
lastPieceClearedLines = false
// Reset piece state // Reset piece state
holdPiece = null holdPiece = null
@ -545,4 +552,9 @@ class GameBoard(
private fun clearLines(): Int { private fun clearLines(): Int {
return linesToClear.size // Return the number of lines that will be cleared return linesToClear.size // Return the number of lines that will be cleared
} }
/**
* Get the current combo count
*/
fun getCombo(): Int = combo
} }

View file

@ -83,6 +83,15 @@
android:textSize="24sp" android:textSize="24sp"
android:fontFamily="sans-serif-light" android:fontFamily="sans-serif-light"
tools:text="Lines: 0" /> tools:text="Lines: 0" />
<TextView
android:id="@+id/comboText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="24sp"
android:fontFamily="sans-serif-light"
tools:text="Combo: 0" />
</LinearLayout> </LinearLayout>
<!-- Next Piece Preview --> <!-- Next Piece Preview -->