diff --git a/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/FallingBalls.kt b/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/FallingBalls.kt index e3f444b01c..5774ced90b 100644 --- a/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/FallingBalls.kt +++ b/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/FallingBalls.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import org.jetbrains.skiko.KotlinBackend +import kotlin.math.round @Composable fun FallingBalls(game: Game) { @@ -24,13 +25,13 @@ fun FallingBalls(game: Game) { fontSize = 1.8f.em, color = Color(218, 120, 91) ) - Text("Score: ${game.score} Time: ${game.elapsed / 1_000_000} Blocks: ${game.numBlocks}", fontSize = 1.8f.em) + Text("Score: ${game.score} Time: ${game.elapsed / 1_000_000} Blocks: ${game.numBlocks.toInt()}", fontSize = 1.8f.em) Row { if (!game.started) { Slider( value = game.numBlocks / 20f, - onValueChange = { game.numBlocks = (it * 20f).toInt().coerceAtLeast(1) }, - modifier = Modifier.width(100.dp) + onValueChange = { game.numBlocks = (it * 20f).coerceAtLeast(1f) }, + modifier = Modifier.width(250.dp) ) } Button( diff --git a/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/Game.kt b/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/Game.kt index 8c65b92abe..b4bbe9d4a8 100644 --- a/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/Game.kt +++ b/experimental/examples/falling-balls-mpp/src/commonMain/kotlin/fallingBalls/Game.kt @@ -33,7 +33,7 @@ class Game(val time: Time) { var paused by mutableStateOf(false) var finished by mutableStateOf(false) - var numBlocks by mutableStateOf(5) + var numBlocks by mutableStateOf(5f) fun start() { previousTimeNanos = time.now() @@ -43,7 +43,7 @@ class Game(val time: Time) { finished = false paused = false pieces.clear() - repeat(numBlocks) { index -> + repeat(numBlocks.toInt()) { index -> pieces.add(PieceData(this, index * 1.5f + 5f, colors[index % colors.size]).also { piece -> piece.position = Random.nextDouble(0.0, 100.0).toFloat() }) @@ -65,7 +65,7 @@ class Game(val time: Time) { fun clicked(piece: PieceData) { score += piece.velocity.toInt() clicked++ - if (clicked == numBlocks) { + if (clicked == numBlocks.toInt()) { finished = true } }