Orbit Arcade: Brick Break, and the honeycomb grows a row
A paddle, a ball and a wall of bricks for the remote (Paul's approved list): hold left or right to move, OK to launch, Back to pause. Where the ball meets the paddle sets its angle; two-hit bricks; four Orbit layouts that cycle, each wall a little faster; three balls; best score kept on the box. The arcade's honeycomb now holds Snake and OrbitHive over Block Drop and Brick Break. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.platform.LocalWindowInfo
|
||||
import androidx.compose.ui.text.font.Font
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.tv.material3.Text
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.sqrt
|
||||
|
||||
/**
|
||||
* Brick Break for Orbit Arcade (from the game list Paul approved on 2 November 2026): a paddle, a ball and a wall of bricks,
|
||||
* played on the remote. Hold left or right to move, OK to launch, Back to pause. Where the ball meets the paddle sets its angle;
|
||||
* each wall cleared brings a new layout and a slightly faster ball. Three lives. Orbit's own look and layouts.
|
||||
*/
|
||||
internal const val BRICK_W = 320f
|
||||
internal const val BRICK_H = 240f
|
||||
internal const val BRICK_COLS = 10
|
||||
private const val BRICK_ROWS = 6
|
||||
private const val BRICK_TOP = 28f
|
||||
private const val BRICK_HEIGHT = 10f
|
||||
private const val PADDLE_Y = 226f
|
||||
private const val PADDLE_W = 48f
|
||||
private const val PADDLE_SPEED = 230f
|
||||
internal const val BALL_R = 3f
|
||||
|
||||
internal data class Brick(val col: Int, val row: Int, val hits: Int) {
|
||||
val left get() = col * (BRICK_W / BRICK_COLS) + 1f
|
||||
val right get() = left + BRICK_W / BRICK_COLS - 2f
|
||||
val top get() = BRICK_TOP + row * (BRICK_HEIGHT + 2f)
|
||||
val bottom get() = top + BRICK_HEIGHT
|
||||
}
|
||||
|
||||
/** Each level's wall: a pattern over the 10 by 6 grid (0 empty, 1 one hit, 2 two hits), cycling after the last. */
|
||||
private val BrickLayouts = listOf(
|
||||
List(BRICK_ROWS) { "1111111111" },
|
||||
listOf("2222222222", "1111111111", "1100110011", "1111111111", "0111111110", "0011111100"),
|
||||
listOf("1010101010", "0101010101", "2222222222", "1010101010", "0101010101", "1111111111"),
|
||||
listOf("0002222000", "0021111200", "0211111120", "2111111112", "0211111120", "0021111200"))
|
||||
|
||||
internal fun bricksFor(level: Int): List<Brick> = BrickLayouts[(level - 1) % BrickLayouts.size].flatMapIndexed { row, line ->
|
||||
line.mapIndexedNotNull { col, c -> (c - '0').takeIf { it > 0 }?.let { Brick(col, row, it) } }
|
||||
}
|
||||
|
||||
internal data class BrickGame(val paddleX: Float, val ballX: Float, val ballY: Float, val vx: Float, val vy: Float, val bricks: List<Brick>,
|
||||
val launched: Boolean = false, val score: Int = 0, val lives: Int = 3, val level: Int = 1) {
|
||||
val alive get() = lives > 0
|
||||
/** The ball's speed for this level: a little quicker each wall. */
|
||||
val speed get() = 160f + (level - 1) * 18f
|
||||
|
||||
fun launch(): BrickGame = if (launched || !alive) this else copy(launched = true, vx = speed * .45f, vy = -speed * sqrt(1 - .45f * .45f))
|
||||
|
||||
/** [dt] seconds of play, with the paddle moving [move] (-1, 0 or 1); taken in small steps so the ball never skips a brick. */
|
||||
fun step(dt: Float, move: Int): BrickGame {
|
||||
var g = this; var left = dt
|
||||
while (left > 0f && g.alive) { val d = minOf(left, .004f); g = g.tick(d, move); left -= d }
|
||||
return g
|
||||
}
|
||||
|
||||
private fun tick(d: Float, move: Int): BrickGame {
|
||||
val px = (paddleX + move * PADDLE_SPEED * d).coerceIn(PADDLE_W / 2, BRICK_W - PADDLE_W / 2)
|
||||
if (!launched) return copy(paddleX = px, ballX = px, ballY = PADDLE_Y - BALL_R - 1)
|
||||
var x = ballX + vx * d; var y = ballY + vy * d; var nvx = vx; var nvy = vy
|
||||
if (x < BALL_R) { x = BALL_R; nvx = abs(nvx) }
|
||||
if (x > BRICK_W - BALL_R) { x = BRICK_W - BALL_R; nvx = -abs(nvx) }
|
||||
if (y < BALL_R) { y = BALL_R; nvy = abs(nvy) }
|
||||
// The paddle: where it's hit sets the angle, from steep in the middle to shallow at the ends.
|
||||
if (nvy > 0 && y + BALL_R >= PADDLE_Y && y + BALL_R <= PADDLE_Y + 6 && abs(x - px) <= PADDLE_W / 2 + BALL_R) {
|
||||
val along = ((x - px) / (PADDLE_W / 2)).coerceIn(-1f, 1f) * .8f
|
||||
nvx = speed * along; nvy = -speed * sqrt(1 - along * along); y = PADDLE_Y - BALL_R
|
||||
}
|
||||
var bricks2 = bricks; var score2 = score
|
||||
bricks.firstOrNull { b -> x + BALL_R > b.left && x - BALL_R < b.right && y + BALL_R > b.top && y - BALL_R < b.bottom }?.let { b ->
|
||||
// Bounce off the side it came through: whichever overlap is smaller.
|
||||
val overlapX = minOf(x + BALL_R - b.left, b.right - (x - BALL_R)); val overlapY = minOf(y + BALL_R - b.top, b.bottom - (y - BALL_R))
|
||||
if (overlapX < overlapY) nvx = -nvx else nvy = -nvy
|
||||
bricks2 = if (b.hits > 1) bricks - b + b.copy(hits = b.hits - 1) else bricks - b
|
||||
score2 += 10 * level
|
||||
}
|
||||
if (bricks2.isEmpty()) {
|
||||
// Wall cleared: the next layout, the ball back on the paddle.
|
||||
return copy(paddleX = px, ballX = px, ballY = PADDLE_Y - BALL_R - 1, vx = 0f, vy = 0f, bricks = bricksFor(level + 1), launched = false, score = score2 + 100 * level, level = level + 1)
|
||||
}
|
||||
if (y > BRICK_H + BALL_R) return copy(paddleX = px, ballX = px, ballY = PADDLE_Y - BALL_R - 1, vx = 0f, vy = 0f, launched = false, lives = lives - 1, bricks = bricks2, score = score2)
|
||||
return copy(paddleX = px, ballX = x, ballY = y, vx = nvx, vy = nvy, bricks = bricks2, score = score2)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun start() = BrickGame(BRICK_W / 2, BRICK_W / 2, PADDLE_Y - BALL_R - 1, 0f, 0f, bricksFor(1))
|
||||
}
|
||||
}
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
|
||||
@Composable
|
||||
internal fun BrickField(game: BrickGame, modifier: Modifier) = Canvas(modifier) {
|
||||
val k = minOf(size.width / BRICK_W, size.height / BRICK_H)
|
||||
val o = Offset((size.width - BRICK_W * k) / 2, (size.height - BRICK_H * k) / 2)
|
||||
drawRect(Color(0xFF050E2A), o, Size(BRICK_W * k, BRICK_H * k))
|
||||
game.bricks.forEach { b ->
|
||||
val colour = BlockColours[(b.row + b.col / 5) % BlockColours.size]
|
||||
drawRoundRect(if (b.hits > 1) Color.White else colour, Offset(o.x + b.left * k, o.y + b.top * k), Size((b.right - b.left) * k, BRICK_HEIGHT * k), CornerRadius(2 * k))
|
||||
if (b.hits > 1) drawRoundRect(colour, Offset(o.x + (b.left + 1.5f) * k, o.y + (b.top + 1.5f) * k), Size((b.right - b.left - 3f) * k, (BRICK_HEIGHT - 3f) * k), CornerRadius(1.5f * k))
|
||||
}
|
||||
drawRoundRect(Yellow, Offset(o.x + (game.paddleX - PADDLE_W / 2) * k, o.y + PADDLE_Y * k), Size(PADDLE_W * k, 6 * k), CornerRadius(3 * k))
|
||||
drawCircle(Color.White, BALL_R * k, Offset(o.x + game.ballX * k, o.y + game.ballY * k))
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun BrickBreakScreen(best: Int, onBest: (Int) -> Unit, onLeave: () -> Unit) {
|
||||
var game by remember { mutableStateOf(BrickGame.start()) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var held by remember { mutableIntStateOf(0) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val windowFocused = LocalWindowInfo.current.isWindowFocused
|
||||
LaunchedEffect(windowFocused) { if (!windowFocused && game.alive) paused = true }
|
||||
LaunchedEffect(paused, game.alive) {
|
||||
var last = withFrameNanos { it }
|
||||
while (!paused && game.alive) {
|
||||
val now = withFrameNanos { it }
|
||||
game = game.step(((now - last) / 1e9f).coerceAtMost(.05f), held); last = now
|
||||
}
|
||||
if (!game.alive && game.score > best) onBest(game.score)
|
||||
}
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
BackHandler { if (game.alive) paused = !paused else onLeave() }
|
||||
Row(Modifier.fillMaxSize().background(Navy).padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (paused || !game.alive) return@onPreviewKeyEvent false
|
||||
val down = native.action == KeyEvent.ACTION_DOWN
|
||||
when (native.keyCode) {
|
||||
// Held to move: the remote repeats the press, and letting go stops the paddle.
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> { held = if (down) -1 else if (held == -1) 0 else held; true }
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> { held = if (down) 1 else if (held == 1) 0 else held; true }
|
||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> { if (down) game = game.launch(); true }
|
||||
else -> false
|
||||
}
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(190.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("BRICK BREAK", color = Honey, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("SCORE", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.score.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("BEST", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(maxOf(best, game.score).toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("WALL ${game.level} · BALLS ${game.lives}", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄► Hold to move", color = Muted, fontSize = 13.sp)
|
||||
Text("OK Launch Back Pause", color = Muted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight().border(2.dp, Blue), contentAlignment = Alignment.Center) {
|
||||
BrickField(game, Modifier.fillMaxSize().padding(6.dp))
|
||||
if (game.alive && !game.launched && !paused) Text("Press OK to launch", Modifier.align(Alignment.BottomCenter).padding(bottom = 40.dp), color = Honey, fontSize = 16.sp)
|
||||
if (paused || !game.alive) Column(Modifier.background(Navy, RoundedCornerShape(6.dp)).border(2.dp, Honey, RoundedCornerShape(6.dp)).padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(if (game.alive) "PAUSED" else "GAME OVER", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
if (!game.alive) Text(if (game.score > best) "New best: ${game.score}" else "Score: ${game.score}", color = Color.White, fontSize = 16.sp)
|
||||
OrbitButton(if (game.alive) "Carry on" else "Play again", Modifier.width(200.dp).focusRequester(menuFocus), onClick = {
|
||||
if (!game.alive) game = BrickGame.start()
|
||||
held = 0; paused = false
|
||||
})
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = onLeave)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,8 @@ private fun OrbitHiveScreen(onLeave: () -> Unit) {
|
||||
private enum class ArcadeGame(val title: String, val blurb: String) {
|
||||
Snake("SNAKE", "Eat, grow, and don't hit the walls or yourself."),
|
||||
Hive("ORBITHIVE", "Fire flowers into the honeycomb, and clear the hive before it reaches you."),
|
||||
Blocks("BLOCK DROP", "Turn and drop the falling blocks, and clear full rows before the stack reaches the top.")
|
||||
Blocks("BLOCK DROP", "Turn and drop the falling blocks, and clear full rows before the stack reaches the top."),
|
||||
Bricks("BRICK BREAK", "Keep the ball in play with your paddle and break every brick in the wall.")
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -312,7 +313,7 @@ private fun GameTile(game: ArcadeGame, focus: FocusRequester?, nav: FocusRequest
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
Box((if (focus != null) Modifier.focusRequester(focus) else Modifier).size(135.dp).focusProperties { if (nav != null) up = nav }.onFocusChanged { focused = it.isFocused; if (it.isFocused) onFocus() }.clickable(onClick = onPlay), contentAlignment = Alignment.Center) {
|
||||
Canvas(Modifier.fillMaxSize()) { drawPath(hexagon(center, size.minDimension / 2), if (focused) Yellow else Panel) }
|
||||
Text(when (game) { ArcadeGame.Snake -> "Snake"; ArcadeGame.Hive -> "OrbitHive"; ArcadeGame.Blocks -> "Block Drop" }, color = if (focused) Navy else Color.White, fontSize = 18.sp, fontWeight = FontWeight.SemiBold)
|
||||
Text(when (game) { ArcadeGame.Snake -> "Snake"; ArcadeGame.Hive -> "OrbitHive"; ArcadeGame.Blocks -> "Block Drop"; ArcadeGame.Bricks -> "Brick Break" }, color = if (focused) Navy else Color.White, fontSize = 18.sp, fontWeight = FontWeight.SemiBold)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,12 +324,14 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
|
||||
val settings = remember { OrbitSettings(context) }
|
||||
var best by remember { mutableIntStateOf(settings.snakeBest) }
|
||||
var blockBest by remember { mutableIntStateOf(settings.blockDropBest) }
|
||||
var brickBest by remember { mutableIntStateOf(settings.brickBreakBest) }
|
||||
var playing by remember { mutableStateOf<ArcadeGame?>(null) }
|
||||
var chosen by remember { mutableStateOf(ArcadeGame.Snake) }
|
||||
DisposableEffect(playing) { onPlaying(playing != null); onDispose { onPlaying(false) } }
|
||||
when (playing) {
|
||||
ArcadeGame.Snake -> { SnakeScreen(best, onBest = { best = it; settings.snakeBest = it }, onLeave = { playing = null }); return }
|
||||
ArcadeGame.Hive -> { OrbitHiveScreen(onLeave = { playing = null }); return }
|
||||
ArcadeGame.Bricks -> { BrickBreakScreen(brickBest, onBest = { brickBest = it; settings.brickBreakBest = it }, onLeave = { playing = null }); return }
|
||||
ArcadeGame.Blocks -> { BlockDropScreen(blockBest, onBest = { blockBest = it; settings.blockDropBest = it }, onLeave = { playing = null }); return }
|
||||
null -> {}
|
||||
}
|
||||
@@ -340,6 +343,7 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
|
||||
val board = List(BLOCK_ROWS) { y -> IntArray(BLOCK_COLUMNS) { x -> if (y >= 16 && (x + y) % 9 != 0) 1 + (x * 3 + y) % 7 else 0 } }
|
||||
BlockGame(board, BlockPiece(2, 1, 4, 9), 0, emptyList())
|
||||
}
|
||||
val brickPreview = remember { BrickGame.start().copy(bricks = bricksFor(2), ballX = 180f, ballY = 150f, paddleX = 150f) }
|
||||
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.weight(1f).fillMaxHeight().background(Panel, RoundedCornerShape(6.dp)).padding(14.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
@@ -347,6 +351,7 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
|
||||
Box(Modifier.fillMaxWidth().weight(1f).background(Color(0xFF050E2A))) {
|
||||
if (chosen == ArcadeGame.Snake) SnakeField(preview, Modifier.fillMaxSize())
|
||||
else if (chosen == ArcadeGame.Blocks) BlockField(blockPreview, Modifier.fillMaxSize().padding(8.dp))
|
||||
else if (chosen == ArcadeGame.Bricks) BrickField(brickPreview, Modifier.fillMaxSize().padding(8.dp))
|
||||
else Canvas(Modifier.fillMaxSize()) {
|
||||
val colours = listOf(Color(0xFFE53935), Color(0xFF1E66D0), Color(0xFF2E9D3A), Color(0xFFF4F4F4), Color(0xFFF5A623), Color(0xFF8E44AD))
|
||||
val r = size.height / 9
|
||||
@@ -357,7 +362,7 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
|
||||
}
|
||||
}
|
||||
Text(chosen.title, color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
Text(if (chosen == ArcadeGame.Snake && best > 0) "Your best: $best" else if (chosen == ArcadeGame.Blocks && blockBest > 0) "Your best: $blockBest" else chosen.blurb, color = Color.White, fontSize = 15.sp, maxLines = 2)
|
||||
Text(if (chosen == ArcadeGame.Snake && best > 0) "Your best: $best" else if (chosen == ArcadeGame.Blocks && blockBest > 0) "Your best: $blockBest" else if (chosen == ArcadeGame.Bricks && brickBest > 0) "Your best: $brickBest" else chosen.blurb, color = Color.White, fontSize = 15.sp, maxLines = 2)
|
||||
}
|
||||
Column(Modifier.width(290.dp).fillMaxHeight(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
@@ -365,15 +370,17 @@ internal fun OrbitArcade(modifier: Modifier, onPlaying: (Boolean) -> Unit) {
|
||||
GameTile(ArcadeGame.Hive, null, nav, { chosen = ArcadeGame.Hive }, { playing = ArcadeGame.Hive })
|
||||
}
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
GameTile(ArcadeGame.Blocks, null, null, { chosen = ArcadeGame.Blocks }, { playing = ArcadeGame.Blocks })
|
||||
Box(Modifier.size(110.dp), contentAlignment = Alignment.Center) {
|
||||
Canvas(Modifier.fillMaxSize()) { drawPath(hexagon(center, size.minDimension / 2), Panel.copy(alpha = .4f)) }
|
||||
Text("More soon", color = Muted, fontSize = 12.sp)
|
||||
// A honeycomb: each row of two sits in the gaps of the one above.
|
||||
Row(Modifier.offset(y = (-18).dp), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
GameTile(ArcadeGame.Blocks, null, null, { chosen = ArcadeGame.Blocks }, { playing = ArcadeGame.Blocks })
|
||||
GameTile(ArcadeGame.Bricks, null, null, { chosen = ArcadeGame.Bricks }, { playing = ArcadeGame.Bricks })
|
||||
}
|
||||
Box(Modifier.offset(y = (-30).dp).size(84.dp), contentAlignment = Alignment.Center) {
|
||||
Canvas(Modifier.fillMaxSize()) { drawPath(hexagon(center, size.minDimension / 2), Panel.copy(alpha = .4f)) }
|
||||
Text("More soon", color = Muted, fontSize = 11.sp)
|
||||
}
|
||||
}
|
||||
}
|
||||
Text("◄► Choose OK Play Back Main menu", color = Muted, fontSize = 11.sp)
|
||||
Text("◄►▲▼ Choose OK Play Back Main menu", color = Muted, fontSize = 11.sp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ internal class OrbitSettings(context: Context) {
|
||||
var blockDropBest: Int
|
||||
get() = saved.getInt("block_drop_best", 0)
|
||||
set(value) { saved.edit().putInt("block_drop_best", value).apply() }
|
||||
var brickBreakBest: Int
|
||||
get() = saved.getInt("brick_break_best", 0)
|
||||
set(value) { saved.edit().putInt("brick_break_best", value).apply() }
|
||||
var subtitlesOn: Boolean
|
||||
get() = saved.getBoolean("subtitles_on", false)
|
||||
set(value) { saved.edit().putBoolean("subtitles_on", value).apply() }
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import kotlin.math.abs
|
||||
|
||||
/** Brick Break: the ball rides the paddle until launched, bounces off walls and paddle, breaks bricks, and costs a life when missed. */
|
||||
class BrickBreakTest {
|
||||
@Test fun theBallWaitsOnThePaddleUntilLaunched() {
|
||||
val g = BrickGame.start().step(.5f, 1)
|
||||
assertFalse(g.launched); assertEquals(g.paddleX, g.ballX, 0.01f)
|
||||
assertTrue(g.paddleX > BRICK_W / 2)
|
||||
val l = g.launch(); assertTrue(l.launched && l.vy < 0)
|
||||
}
|
||||
|
||||
@Test fun thePaddleStopsAtTheEdges() {
|
||||
assertTrue(BrickGame.start().step(5f, -1).paddleX >= 24f)
|
||||
assertTrue(BrickGame.start().step(5f, 1).paddleX <= BRICK_W - 24f)
|
||||
}
|
||||
|
||||
@Test fun aBrickBreaksAndTheBallTurnsBack() {
|
||||
val one = Brick(4, 5, 1)
|
||||
val g = BrickGame.start().copy(bricks = listOf(one, Brick(0, 0, 1)), launched = true, ballX = (one.left + one.right) / 2, ballY = one.bottom + 6, vx = 0f, vy = -160f)
|
||||
val after = g.step(.1f, 0)
|
||||
assertEquals(listOf(Brick(0, 0, 1)), after.bricks); assertEquals(10, after.score); assertTrue(after.vy > 0)
|
||||
// A two-hit brick takes two.
|
||||
val tough = Brick(4, 5, 2)
|
||||
assertEquals(1, g.copy(bricks = listOf(tough, Brick(0, 0, 1))).step(.1f, 0).bricks.first { it.col == 4 }.hits)
|
||||
}
|
||||
|
||||
@Test fun whereThePaddleIsHitSetsTheAngle() {
|
||||
val g = BrickGame.start().copy(launched = true, bricks = listOf(Brick(0, 0, 1)), paddleX = 160f, ballY = 200f, vx = 0f, vy = 160f)
|
||||
val middle = g.copy(ballX = 160f).step(.2f, 0); val edge = g.copy(ballX = 182f).step(.2f, 0)
|
||||
assertTrue(middle.vy < 0 && edge.vy < 0)
|
||||
assertTrue(abs(edge.vx) > abs(middle.vx))
|
||||
}
|
||||
|
||||
@Test fun aMissedBallCostsALifeAndAClearedWallBringsTheNext() {
|
||||
val missed = BrickGame.start().copy(launched = true, bricks = listOf(Brick(0, 0, 1)), paddleX = 30f, ballX = 300f, ballY = 230f, vx = 0f, vy = 160f).step(.3f, 0)
|
||||
assertEquals(2, missed.lives); assertFalse(missed.launched)
|
||||
val last = Brick(4, 5, 1)
|
||||
val cleared = BrickGame.start().copy(bricks = listOf(last), launched = true, ballX = (last.left + last.right) / 2, ballY = last.bottom + 6, vx = 0f, vy = -160f).step(.1f, 0)
|
||||
assertEquals(2, cleared.level); assertEquals(bricksFor(2), cleared.bricks); assertTrue(cleared.speed > BrickGame.start().speed)
|
||||
assertFalse(BrickGame.start().copy(lives = 0).alive)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user