mirror of
https://github.com/cmclark00/mintris.git
synced 2025-05-18 15:25:20 +01:00
Add combo system that tracks consecutive line clears with next piece
This commit is contained in:
parent
2c7639a861
commit
44c4c73feb
4 changed files with 54 additions and 8 deletions
|
@ -203,6 +203,7 @@ class MainActivity : AppCompatActivity() {
|
|||
binding.scoreText.text = score.toString()
|
||||
binding.currentLevelText.text = level.toString()
|
||||
binding.linesText.text = lines.toString()
|
||||
binding.comboText.text = gameBoard.getCombo().toString()
|
||||
|
||||
// Force redraw of next piece preview
|
||||
binding.nextPieceView.invalidate()
|
||||
|
|
|
@ -10,6 +10,8 @@ import android.view.MotionEvent
|
|||
import android.view.View
|
||||
import java.util.Random
|
||||
import android.util.Log
|
||||
import com.mintris.model.HighScoreManager
|
||||
import com.mintris.model.HighScore
|
||||
|
||||
class TitleScreen @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -21,6 +23,7 @@ class TitleScreen @JvmOverloads constructor(
|
|||
private val glowPaint = Paint()
|
||||
private val titlePaint = Paint()
|
||||
private val promptPaint = Paint()
|
||||
private val highScorePaint = Paint()
|
||||
private val cellSize = 30f
|
||||
private val random = Random()
|
||||
private var width = 0
|
||||
|
@ -108,6 +111,16 @@ class TitleScreen @JvmOverloads constructor(
|
|||
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)
|
||||
paint.apply {
|
||||
color = Color.WHITE
|
||||
|
@ -239,8 +252,19 @@ class TitleScreen @JvmOverloads constructor(
|
|||
val titleY = height * 0.4f
|
||||
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
|
||||
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
|
||||
invalidate()
|
||||
|
|
|
@ -37,6 +37,7 @@ class GameBoard(
|
|||
private var lastClearWasTetris = false
|
||||
private var lastClearWasPerfect = false
|
||||
private var lastClearWasAllClear = false
|
||||
private var lastPieceClearedLines = false // Track if the last piece placed cleared lines
|
||||
|
||||
// Animation state
|
||||
var linesToClear = mutableListOf<Int>()
|
||||
|
@ -326,6 +327,18 @@ class GameBoard(
|
|||
calculateScore(shiftAmount)
|
||||
}.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
|
||||
}.start()
|
||||
|
||||
// Update combo counter
|
||||
if (clearedLines > 0) {
|
||||
combo++
|
||||
} else {
|
||||
combo = 0
|
||||
}
|
||||
|
||||
// Update line clear state
|
||||
lastClearWasTetris = clearedLines == 4
|
||||
lastClearWasPerfect = isPerfectClear
|
||||
|
@ -528,6 +534,7 @@ class GameBoard(
|
|||
lastClearWasTetris = false
|
||||
lastClearWasPerfect = false
|
||||
lastClearWasAllClear = false
|
||||
lastPieceClearedLines = false
|
||||
|
||||
// Reset piece state
|
||||
holdPiece = null
|
||||
|
@ -545,4 +552,9 @@ class GameBoard(
|
|||
private fun clearLines(): Int {
|
||||
return linesToClear.size // Return the number of lines that will be cleared
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current combo count
|
||||
*/
|
||||
fun getCombo(): Int = combo
|
||||
}
|
|
@ -83,6 +83,15 @@
|
|||
android:textSize="24sp"
|
||||
android:fontFamily="sans-serif-light"
|
||||
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>
|
||||
|
||||
<!-- Next Piece Preview -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue