Classics family pass (0.111.0, versionCode 301): Back by context, family title/play/result, bug fixes, backdrop collection
- Back undoes what's in hand first (Patience's held card, Blast Off's tray), otherwise pauses; one rule, backStep/gameKeys - All eight Classics on the shared title, play frame, pause and result, in ArcadeColours and Anton, with KeyFooter keys - Patience controls fixed: Up to the top row, OK twice sends home, refused moves say so, distinct held/pointer, bigger cards - Star Chase maze with no lone walls or dead ends, solid walls, bigger stars; Comet Trail turn queue; paddle slide, held-Up spin, Zip-while-paused and Skydoku's main-thread puzzle making fixed - Eight code-drawn backdrops, one per Classic by default or one chosen for all; old choices carried over - Difficulty paces the four clock games (Normal unchanged); scores, Household keys and Skydoku's count untouched Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -12,65 +15,216 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.drawscope.rotate
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.sin
|
||||
import kotlin.random.Random
|
||||
|
||||
/**
|
||||
* The Arcade's backdrops (Paul, 6 November 2026, from the Arcade extras sheet): one chosen in the Arcade, behind every game
|
||||
* but Comet Trail (which keeps its own changing skies) and Patience (its card table). Drawn once and kept, not animated, so
|
||||
* a game never pays for it frame by frame; each game keeps its own dark playing panel on top.
|
||||
* The Arcade's backdrops (Paul, 9 November 2026: "new updated backdrops across all games, perhaps a small collection"):
|
||||
* night skies in Orbit's style, drawn in code (no pictures, so nothing to load and next to no memory). Each Classic has
|
||||
* one that suits it, unless one is chosen for every game in Arcade Settings. They're still: drawn into their own layer and
|
||||
* replayed, never redrawn frame by frame, so Reduce motion has nothing to stop. Dimmed, so the game reads first.
|
||||
*
|
||||
* More drop in as entries here (approved for later: Seaside Pier, Drive-In, Snowfall, Sakura Night, Retro Living Room,
|
||||
* Moon Base): a title, a drawing in [arcadeBackdrop], and the Backdrop button picks them up.
|
||||
*/
|
||||
internal enum class ArcadeBackdrop(val title: String) { NightSky("Night Sky"), Nebula("Nebula"), Moonrise("Moonrise") }
|
||||
internal enum class ArcadeBackdrop(val title: String) {
|
||||
DeepSpace("Deep Space"), Aurora("Aurora"), Rooftops("Rooftops"), SatelliteRing("Satellite Ring"),
|
||||
Nebula("Nebula"), TestCardDusk("Test-Card Dusk"), Meadow("Meadow at Night"), Teletext("Teletext Grid");
|
||||
|
||||
companion object {
|
||||
/** A saved choice, read back. Before the collection there were three: Night Sky (the default, so "each game's own" now), Nebula and Moonrise. */
|
||||
fun parse(saved: String?): ArcadeBackdrop? = when (saved) {
|
||||
null, "", "Auto", "NightSky" -> null
|
||||
"Moonrise" -> Rooftops
|
||||
else -> entries.firstOrNull { it.name == saved }
|
||||
}
|
||||
|
||||
/** Each Classic's own (the Originals draw their own fields). */
|
||||
fun forGame(id: String): ArcadeBackdrop = when (id) {
|
||||
"OrbMan" -> DeepSpace
|
||||
"Blast" -> Nebula
|
||||
"Sky" -> SatelliteRing
|
||||
"Snake" -> DeepSpace
|
||||
"Blocks" -> Teletext
|
||||
"Bricks" -> Rooftops
|
||||
"Pairs" -> TestCardDusk
|
||||
"Patience" -> Meadow
|
||||
else -> DeepSpace
|
||||
}
|
||||
|
||||
/** Comet Trail's skies change as the score climbs, as they always have, now through the collection. */
|
||||
val cometSkies = listOf(DeepSpace, Nebula, SatelliteRing, Aurora)
|
||||
}
|
||||
}
|
||||
|
||||
internal object ArcadeLook {
|
||||
var backdrop by mutableStateOf(ArcadeBackdrop.NightSky)
|
||||
/** Chosen for every game, or null for each game's own. */
|
||||
var choice by mutableStateOf<ArcadeBackdrop?>(null)
|
||||
|
||||
fun load(settings: OrbitSettings) { backdrop = ArcadeBackdrop.entries.firstOrNull { it.name == settings.arcadeBackdrop } ?: ArcadeBackdrop.NightSky }
|
||||
val title get() = choice?.title ?: "Each game's own"
|
||||
|
||||
/** The next one along, for the Arcade's Backdrop button. */
|
||||
fun load(settings: OrbitSettings) { choice = ArcadeBackdrop.parse(settings.arcadeBackdrop) }
|
||||
|
||||
/** The next one along, for the Arcade's Backdrop button: each game's own, then each in turn. */
|
||||
fun next(settings: OrbitSettings) {
|
||||
backdrop = ArcadeBackdrop.entries[(backdrop.ordinal + 1) % ArcadeBackdrop.entries.size]
|
||||
settings.arcadeBackdrop = backdrop.name
|
||||
val all = listOf<ArcadeBackdrop?>(null) + ArcadeBackdrop.entries
|
||||
choice = all[(all.indexOf(choice) + 1) % all.size]
|
||||
settings.arcadeBackdrop = choice?.name ?: "Auto"
|
||||
}
|
||||
|
||||
fun forGame(id: String) = choice ?: ArcadeBackdrop.forGame(id)
|
||||
|
||||
/** Comet Trail: the chosen one throughout, or its changing skies. */
|
||||
fun comet(score: Int) = choice ?: ArcadeBackdrop.cometSkies[snakeBackdrop(score)]
|
||||
}
|
||||
|
||||
private val BackdropNavy = Color(0xFF071632)
|
||||
|
||||
/** The chosen backdrop behind a game, in place of its plain navy. */
|
||||
internal fun Modifier.arcadeBackdrop(which: ArcadeBackdrop = ArcadeLook.backdrop): Modifier = drawWithCache {
|
||||
/**
|
||||
* The backdrop as a layer of its own behind a screen: the game's canvas redraws every frame, this doesn't (in its own
|
||||
* layer, a redraw above it just replays it).
|
||||
*/
|
||||
@Composable
|
||||
internal fun ArcadeBackdropLayer(which: ArcadeBackdrop, modifier: Modifier = Modifier) {
|
||||
Box(modifier.fillMaxSize().graphicsLayer().arcadeBackdrop(which))
|
||||
}
|
||||
|
||||
/** The stars of a backdrop: x, y and radius, made once per size. */
|
||||
private fun starField(seed: Int, n: Int, w: Float, h: Float, top: Float = 1f): FloatArray {
|
||||
val rnd = Random(seed); val out = FloatArray(n * 3)
|
||||
for (i in 0 until n) { out[i * 3] = rnd.nextFloat() * w; out[i * 3 + 1] = rnd.nextFloat() * h * top; out[i * 3 + 2] = .6f + rnd.nextFloat() * 1.4f }
|
||||
return out
|
||||
}
|
||||
|
||||
internal fun Modifier.arcadeBackdrop(which: ArcadeBackdrop): Modifier = drawWithCache {
|
||||
val w = size.width; val h = size.height
|
||||
val rnd = Random(which.ordinal + 11)
|
||||
val stars = List(if (which == ArcadeBackdrop.Moonrise) 40 else 90) { Triple(rnd.nextFloat() * w, rnd.nextFloat() * h * (if (which == ArcadeBackdrop.Moonrise) .6f else 1f), .6f + rnd.nextFloat() * 1.4f) }
|
||||
val skyline = Path().apply {
|
||||
moveTo(0f, h); var x = 0f; lineTo(0f, h * .8f)
|
||||
while (x < w) { val top = h * (.62f + rnd.nextFloat() * .2f); val step = w * (.03f + rnd.nextFloat() * .04f); lineTo(x, top); lineTo(x + step, top); x += step }
|
||||
lineTo(w, h); close()
|
||||
val rnd = Random(which.ordinal * 31 + 7)
|
||||
val stars = starField(which.ordinal + 11, when (which) { ArcadeBackdrop.DeepSpace -> 130; ArcadeBackdrop.Rooftops, ArcadeBackdrop.Meadow -> 60; else -> 90 }, w, h,
|
||||
top = when (which) { ArcadeBackdrop.Rooftops -> .62f; ArcadeBackdrop.Meadow -> .6f; ArcadeBackdrop.TestCardDusk -> .7f; else -> 1f })
|
||||
// Shapes, made once: the skyline, the hills, ribbons of light.
|
||||
val skyline = Path(); val windows = ArrayList<Offset>(); val aerials = ArrayList<Offset>()
|
||||
val hills = Path(); val hillsBack = Path(); val flowers = ArrayList<Pair<Offset, Color>>()
|
||||
val ribbons = ArrayList<Path>()
|
||||
when (which) {
|
||||
ArcadeBackdrop.Rooftops -> {
|
||||
skyline.moveTo(0f, h); skyline.lineTo(0f, h * .8f); var x = 0f
|
||||
while (x < w) {
|
||||
val top = h * (.62f + rnd.nextFloat() * .2f); val step = w * (.035f + rnd.nextFloat() * .045f)
|
||||
skyline.lineTo(x, top); skyline.lineTo(x + step, top)
|
||||
if (rnd.nextFloat() < .3f) aerials += Offset(x + step * .5f, top)
|
||||
for (k in 0 until 3) if (rnd.nextFloat() < .5f) windows += Offset(x + step * (.2f + rnd.nextFloat() * .6f), top + (h - top) * (.15f + rnd.nextFloat() * .7f))
|
||||
x += step
|
||||
}
|
||||
skyline.lineTo(w, h); skyline.close()
|
||||
}
|
||||
ArcadeBackdrop.Meadow -> {
|
||||
hillsBack.moveTo(0f, h); hillsBack.lineTo(0f, h * .7f)
|
||||
hills.moveTo(0f, h); hills.lineTo(0f, h * .82f)
|
||||
for (i in 0..40) {
|
||||
val x = w * i / 40f
|
||||
hillsBack.lineTo(x, h * (.7f + .05f * sin(i * .45 + 1).toFloat()))
|
||||
hills.lineTo(x, h * (.82f + .04f * sin(i * .3).toFloat()))
|
||||
}
|
||||
hillsBack.lineTo(w, h); hillsBack.close(); hills.lineTo(w, h); hills.close()
|
||||
val petals = listOf(Color(0xFFFF4FA3), Color(0xFFFFDE59), Color(0xFFA77BFF), Color(0xFF35D6F2))
|
||||
repeat(46) { flowers += Offset(rnd.nextFloat() * w, h * (.86f + rnd.nextFloat() * .13f)) to petals[it % petals.size] }
|
||||
// Fireflies over the grass.
|
||||
repeat(18) { windows += Offset(rnd.nextFloat() * w, h * (.55f + rnd.nextFloat() * .3f)) }
|
||||
}
|
||||
ArcadeBackdrop.Aurora -> {
|
||||
for (r in 0 until 3) {
|
||||
val p = Path(); val base = h * (.28f + r * .12f); val amp = h * (.06f + r * .02f); val phase = r * 1.7
|
||||
p.moveTo(0f, base)
|
||||
for (i in 0..48) { val x = w * i / 48f; p.lineTo(x, base + amp * sin(i * .26 + phase).toFloat()) }
|
||||
for (i in 48 downTo 0) { val x = w * i / 48f; p.lineTo(x, base + h * .22f + amp * .6f * sin(i * .26 + phase + .6).toFloat()) }
|
||||
p.close(); ribbons += p
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
val windows = List(36) { Offset(rnd.nextFloat() * w, h * (.84f + rnd.nextFloat() * .14f)) }
|
||||
val ringed = Offset(w * .16f, h * 1.02f)
|
||||
val teleCells = if (which == ArcadeBackdrop.Teletext) Random(99).let { m -> IntArray(40 * 24) { m.nextInt(100) } } else IntArray(0)
|
||||
onDrawBehind {
|
||||
fun starsAt(alpha: Float, div: Float) { for (i in 0 until stars.size / 3) drawCircle(Color.White.copy(alpha = alpha + stars[i * 3 + 2] / div), stars[i * 3 + 2], Offset(stars[i * 3], stars[i * 3 + 1])) }
|
||||
when (which) {
|
||||
ArcadeBackdrop.NightSky -> {
|
||||
drawRect(BackdropNavy)
|
||||
stars.forEach { (x, y, r) -> drawCircle(Color.White.copy(alpha = .25f + r / 4), r, Offset(x, y)) }
|
||||
ArcadeBackdrop.DeepSpace -> {
|
||||
drawRect(Brush.verticalGradient(listOf(Color(0xFF040A1E), BackdropNavy)))
|
||||
starsAt(.25f, 4f)
|
||||
// A faint gold orbit, as on the Welcome moment.
|
||||
rotate(-12f, Offset(w / 2, h / 2)) { drawOval(Color(0xFFFFDE59).copy(alpha = .14f), Offset(w * .12f, h * .3f), Size(w * .76f, h * .4f), style = Stroke(2.5f)) }
|
||||
rotate(-12f, Offset(w / 2, h / 2)) { drawOval(Color(0xFFFFDE59).copy(alpha = .13f), Offset(w * .12f, h * .3f), Size(w * .76f, h * .4f), style = Stroke(2.5f)) }
|
||||
}
|
||||
ArcadeBackdrop.Aurora -> {
|
||||
drawRect(Brush.verticalGradient(listOf(Color(0xFF041026), Color(0xFF0A1A3A))))
|
||||
starsAt(.18f, 5f)
|
||||
val tints = listOf(Color(0xFF6EDCAA), Color(0xFF35D6F2), Color(0xFFA77BFF))
|
||||
ribbons.forEachIndexed { r, p -> drawPath(p, Brush.verticalGradient(listOf(tints[r].copy(alpha = .30f), tints[r].copy(alpha = 0f)), h * (.22f + r * .12f), h * (.58f + r * .12f))) }
|
||||
}
|
||||
ArcadeBackdrop.Rooftops -> {
|
||||
drawRect(Brush.verticalGradient(listOf(BackdropNavy, Color(0xFF22305E))))
|
||||
starsAt(.2f, 5f)
|
||||
val moon = Offset(w * .78f, h * .26f); val mr = h * .11f
|
||||
drawCircle(Color(0xFFC9B5FF).copy(alpha = .18f), mr * 1.6f, moon)
|
||||
drawCircle(Color(0xFFC9B5FF), mr, moon)
|
||||
drawCircle(Color(0xFFB59CF5), mr * .2f, moon + Offset(-mr * .3f, -mr * .28f)); drawCircle(Color(0xFFB59CF5), mr * .13f, moon + Offset(mr * .36f, mr * .3f))
|
||||
drawPath(skyline, Color(0xFF061025))
|
||||
// TV aerials on the roofs, and lit windows (some with a telly's blue).
|
||||
aerials.forEach { a -> drawLine(Color(0xFF061025), a, a - Offset(0f, h * .05f), 2.5f); drawLine(Color(0xFF061025), a - Offset(h * .02f, h * .04f), a - Offset(-h * .02f, h * .04f), 2.5f) }
|
||||
windows.forEachIndexed { i, o -> drawRect((if (i % 4 == 0) Color(0xFF35D6F2) else Color(0xFFFFDE59)).copy(alpha = .75f), o, Size(4f, 5f)) }
|
||||
}
|
||||
ArcadeBackdrop.SatelliteRing -> {
|
||||
drawRect(Brush.verticalGradient(listOf(Color(0xFF050C22), Color(0xFF0B1A40))))
|
||||
starsAt(.2f, 5f)
|
||||
val pr = h * .42f
|
||||
drawCircle(Brush.radialGradient(listOf(Color(0xFF3A64C8).copy(alpha = .55f), Color(0xFF13306B).copy(alpha = .5f)), ringed - Offset(pr * .3f, pr * .4f), pr * 1.4f), pr, ringed)
|
||||
rotate(-10f, ringed) {
|
||||
drawOval(Color(0xFFFFDE59).copy(alpha = .28f), Offset(ringed.x - pr * 1.9f, ringed.y - pr * .5f), Size(pr * 3.8f, pr), style = Stroke(3f))
|
||||
drawOval(Color(0xFF35D6F2).copy(alpha = .16f), Offset(ringed.x - pr * 2.2f, ringed.y - pr * .62f), Size(pr * 4.4f, pr * 1.24f), style = Stroke(2f))
|
||||
// Little satellites along the ring, Orbit's own.
|
||||
for (k in 0 until 5) {
|
||||
val a = PI * (1.05 + k * .16); val sx = ringed.x + (pr * 1.9f * kotlin.math.cos(a)).toFloat(); val sy = ringed.y + (pr * .5f * sin(a)).toFloat()
|
||||
drawRect(Color(0xFFF4F6FB).copy(alpha = .7f), Offset(sx - 3f, sy - 2f), Size(6f, 4f)); drawLine(Color(0xFF35D6F2).copy(alpha = .7f), Offset(sx - 9f, sy), Offset(sx + 9f, sy), 1.5f)
|
||||
}
|
||||
}
|
||||
}
|
||||
ArcadeBackdrop.Nebula -> {
|
||||
drawRect(Color(0xFF0A1230))
|
||||
drawCircle(Brush.radialGradient(listOf(OrbCharacter.Drift.colour.copy(alpha = .32f), Color.Transparent), Offset(w * .3f, h * .38f), w * .42f), w * .42f, Offset(w * .3f, h * .38f))
|
||||
drawCircle(Brush.radialGradient(listOf(Color(0xFFA77BFF).copy(alpha = .34f), Color.Transparent), Offset(w * .72f, h * .66f), w * .45f), w * .45f, Offset(w * .72f, h * .66f))
|
||||
stars.forEach { (x, y, r) -> drawCircle(Color.White.copy(alpha = .2f + r / 5), r, Offset(x, y)) }
|
||||
starsAt(.2f, 5f)
|
||||
}
|
||||
ArcadeBackdrop.Moonrise -> {
|
||||
drawRect(Brush.verticalGradient(listOf(BackdropNavy, Color(0xFF22305E))))
|
||||
stars.forEach { (x, y, r) -> drawCircle(Color.White.copy(alpha = .2f + r / 5), r, Offset(x, y)) }
|
||||
val moon = Offset(w * .74f, h * .62f); val mr = h * .2f
|
||||
drawCircle(Color(0xFFC9B5FF), mr, moon)
|
||||
drawCircle(Color(0xFFB59CF5), mr * .2f, moon + Offset(-mr * .3f, -mr * .28f)); drawCircle(Color(0xFFB59CF5), mr * .13f, moon + Offset(mr * .36f, mr * .3f))
|
||||
drawPath(skyline, Color(0xFF061025))
|
||||
windows.forEach { drawRect(Color(0xFFFFDE59).copy(alpha = .8f), it, Size(4f, 4f)) }
|
||||
ArcadeBackdrop.TestCardDusk -> {
|
||||
drawRect(Brush.verticalGradient(listOf(BackdropNavy, Color(0xFF2A1760), Color(0xFF5A2A4A))))
|
||||
starsAt(.18f, 5f)
|
||||
// The test card's bars, low on the horizon like a sunset.
|
||||
val bars = listOf(Color(0xFFF4F6FB), Color(0xFFFFDE59), Color(0xFF35D6F2), Color(0xFF6EDCAA), Color(0xFFFF4FA3), Color(0xFFFF6B6B), Color(0xFFA77BFF))
|
||||
val bw = w / bars.size
|
||||
bars.forEachIndexed { i, c -> drawRect(Brush.verticalGradient(listOf(c.copy(alpha = 0f), c.copy(alpha = .22f)), h * .72f, h), Offset(i * bw, h * .72f), Size(bw + 1f, h * .28f)) }
|
||||
drawCircle(Color(0xFFFF8A3D).copy(alpha = .16f), h * .3f, Offset(w * .5f, h * 1.02f))
|
||||
}
|
||||
ArcadeBackdrop.Meadow -> {
|
||||
drawRect(Brush.verticalGradient(listOf(Color(0xFF061430), Color(0xFF0E2A48))))
|
||||
starsAt(.2f, 5f)
|
||||
drawCircle(Color(0xFFFFE9A8).copy(alpha = .85f), h * .05f, Offset(w * .14f, h * .18f))
|
||||
drawPath(hillsBack, Color(0xFF0B2A2A)); drawPath(hills, Color(0xFF07201C))
|
||||
flowers.forEach { (o, c) -> drawCircle(c.copy(alpha = .7f), 3f, o); drawCircle(Color(0xFFFFDE59).copy(alpha = .8f), 1.2f, o) }
|
||||
windows.forEach { o -> drawCircle(Color(0xFFFFDE59).copy(alpha = .16f), 7f, o); drawCircle(Color(0xFFFFF2A8).copy(alpha = .8f), 1.8f, o) }
|
||||
}
|
||||
ArcadeBackdrop.Teletext -> {
|
||||
drawRect(Color(0xFF02060F))
|
||||
// A faint mosaic in the teletext colours, on a grid, as if a page were showing through.
|
||||
val cols = 40; val rows = 24; val cw = w / cols; val ch = h / rows
|
||||
val tele = listOf(Color(0xFFFF0000), Color(0xFF00FF00), Color(0xFFFFFF00), Color(0xFF0000FF), Color(0xFFFF00FF), Color(0xFF00FFFF), Color(0xFFFFFFFF))
|
||||
for (r in 0 until rows) for (c in 0 until cols) {
|
||||
val v = teleCells[r * cols + c]
|
||||
if (v < 9) drawRect(tele[v % tele.size].copy(alpha = .09f), Offset(c * cw, r * ch), Size(cw, ch))
|
||||
}
|
||||
for (r in 0..rows) drawLine(Color(0xFF35D6F2).copy(alpha = .05f), Offset(0f, r * ch), Offset(w, r * ch), 1f)
|
||||
for (c in 0..cols) drawLine(Color(0xFF35D6F2).copy(alpha = .05f), Offset(c * cw, 0f), Offset(c * cw, h), 1f)
|
||||
drawRect(Color(0xFF0000FF).copy(alpha = .16f), Offset.Zero, Size(w, ch))
|
||||
}
|
||||
}
|
||||
// Dimmed, so the game always reads first.
|
||||
drawRect(BackdropNavy.copy(alpha = .35f))
|
||||
drawRect(BackdropNavy.copy(alpha = .3f))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.previousLine
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.PauseWhenHidden
|
||||
import tv.orbit.classic.arcade.RepeatGuard
|
||||
@@ -140,9 +156,6 @@ internal class BlastGame(
|
||||
}
|
||||
}
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
|
||||
private fun DrawScope.blastBlock(at: Offset, cell: Float, colour: Color, alpha: Float = 1f) {
|
||||
val pad = cell * .06f
|
||||
drawRoundRect(colour.copy(alpha = alpha), at + Offset(pad, pad), Size(cell - 2 * pad, cell - 2 * pad), CornerRadius(cell * .18f))
|
||||
@@ -153,7 +166,7 @@ private fun DrawScope.blastBlock(at: Offset, cell: Float, colour: Color, alpha:
|
||||
internal fun DrawScope.drawBlastBoard(game: BlastGame, showPiece: Boolean = true) {
|
||||
val cell = size.minDimension / BLAST_SIZE
|
||||
val origin = Offset((size.width - cell * BLAST_SIZE) / 2, (size.height - cell * BLAST_SIZE) / 2)
|
||||
drawRoundRect(Color(0xFF0A1850), origin - Offset(6f, 6f), Size(cell * BLAST_SIZE + 12f, cell * BLAST_SIZE + 12f), CornerRadius(cell * .2f))
|
||||
drawRoundRect(ArcadeColours.Night, origin - Offset(6f, 6f), Size(cell * BLAST_SIZE + 12f, cell * BLAST_SIZE + 12f), CornerRadius(cell * .2f))
|
||||
for (r in 0 until BLAST_SIZE) for (c in 0 until BLAST_SIZE) {
|
||||
val at = origin + Offset(c * cell, r * cell)
|
||||
val v = game.board[r][c]
|
||||
@@ -177,67 +190,81 @@ private fun DrawScope.drawTrayPiece(p: BlastPiece, cell: Float) {
|
||||
|
||||
@Composable
|
||||
internal fun BlastOffScreen(play: ArcadePlay) {
|
||||
val best = play.best
|
||||
val gameDef = ArcadeGames.Blast
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val calm = Motion.reduce
|
||||
val random = remember { java.util.Random() }
|
||||
var game by remember { mutableStateOf(BlastGame.start(random)) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
// Holding OK places one shape, not one after another (audit finding 8).
|
||||
val guard = remember { RepeatGuard() }
|
||||
PauseWhenHidden(game.alive) { paused = true; guard.reset() }
|
||||
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
// Every run is saved when it ends, however it ends (Arcade Stage C): game over, Leave, or the screen going away.
|
||||
fun pause() { paused = true; guard.reset() }
|
||||
PauseWhenHidden(stage == ClassicStage.Play && !paused) { pause() }
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false) }
|
||||
LaunchedEffect(game.alive) { if (game.alive) run.begin() else run.end(RunEnd(game.score, finished = true)) }
|
||||
// Zip zooms past on a combo.
|
||||
fun startRun() { bestBefore = latestPlay.best; game = BlastGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.score, finished = !game.alive)); latestPlay.onLeave() }
|
||||
LaunchedEffect(game.alive) { if (!game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true)); stage = ClassicStage.Result } }
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
// Zip zooms past on a combo; the flight stops while paused (it used to run on behind the pause menu).
|
||||
var zipAt by remember { mutableLongStateOf(-1L) }
|
||||
var now by remember { mutableLongStateOf(0L) }
|
||||
LaunchedEffect(zipAt) { if (zipAt >= 0 && !calm) { val start = withFrameMillis { it }; while (true) { val t = withFrameMillis { it } - start; now = t; if (t > 1_200) { zipAt = -1; break } } } }
|
||||
// The best as it stood while this game was played, so the new best still shows once it's been saved; Zip and Blaze cheer it.
|
||||
val bestBefore = remember(game.alive) { best }
|
||||
val newBest = game.score > bestBefore && game.score > 0
|
||||
BackHandler { if (game.alive) paused = !paused else play.onLeave() }
|
||||
Row(Modifier.fillMaxSize().arcadeBackdrop().padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
LaunchedEffect(zipAt, paused) {
|
||||
if (zipAt < 0 || calm || paused) return@LaunchedEffect
|
||||
val start = withFrameMillis { it } - now
|
||||
while (true) { val t = withFrameMillis { it } - start; now = t; if (t > 1_200) { zipAt = -1; now = 0; break } }
|
||||
}
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { if (game.inTray) game = game.move(0, -1) else pause() }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Fit them in, light them up!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "Clear lines on placings in a row for a combo: it multiplies every clear.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused,
|
||||
// Back by context: choosing in the tray, Back goes back to the board with the shape you had; on the board it pauses.
|
||||
active = { game.inTray }, cancel = { game = game.move(0, -1) }, pause = ::pause) { key, native ->
|
||||
// Releases are always noted, so the guard knows OK was let go even if the game paused meanwhile.
|
||||
if (native.action == KeyEvent.ACTION_UP) { guard.accept(native); return@onPreviewKeyEvent false }
|
||||
if (native.action != KeyEvent.ACTION_DOWN || paused || !game.alive) return@onPreviewKeyEvent false
|
||||
val next = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> game.move(-1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> game.move(1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_UP -> game.move(0, -1)
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> game.move(0, 1)
|
||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> if (!guard.accept(native)) game else game.press(random).also { if (it.lastCleared >= 2 || it.streak >= 2) zipAt = System.currentTimeMillis() }
|
||||
if (native.action == KeyEvent.ACTION_UP) { guard.accept(native); return@gameKeys false }
|
||||
if (native.action != KeyEvent.ACTION_DOWN || !game.alive) return@gameKeys false
|
||||
val next = when (key) {
|
||||
ArcadeKey.Left -> game.move(-1, 0)
|
||||
ArcadeKey.Right -> game.move(1, 0)
|
||||
ArcadeKey.Up -> game.move(0, -1)
|
||||
ArcadeKey.Down -> game.move(0, 1)
|
||||
ArcadeKey.Ok -> if (!guard.accept(native)) game else game.press(random).also { if (it.lastCleared >= 2 || it.streak >= 2) { now = 0; zipAt = System.currentTimeMillis() } }
|
||||
else -> null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(180.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("BLAST OFF", color = Honey, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("SCORE", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.score.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("BEST", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(maxOf(best, game.score).toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
if (game.streak >= 2) Text("COMBO ×${game.streak}", color = Color(0xFFFF4FA3), fontFamily = Marquee, fontSize = 26.sp)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄►▲▼ Move the shape", color = NightMuted, fontSize = 13.sp)
|
||||
Text("OK Place it", color = NightMuted, fontSize = 13.sp)
|
||||
Text("▼ off the board: choose another", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Back Pause", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ClassicPlayFrame(backdrop, keys,
|
||||
footer = if (game.inTray) listOf(Control("◀▶", "Choose a shape"), Control("OK", "Take it"), Control("▲", "Back to the board"), Control("Back", "Back to the board"))
|
||||
else listOf(Control("◀▶▲▼", "Move the shape"), Control("OK", "Place it"), Control("▼", "Off the board: the tray"), Control("Back", "Pause")),
|
||||
hud = {
|
||||
HudLabel("SCORE"); HudValue("%,d".format(game.score))
|
||||
HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score)))
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("COMBO")
|
||||
HudValue(if (game.streak >= 1) "×${game.streak}" else "—", if (game.streak >= 2) ArcadeColours.Pink else ArcadeColours.Ink)
|
||||
Text(if (game.streak >= 1) "clear again to keep it" else "clear a line to start one", color = ArcadeColours.Muted, fontSize = 14.sp)
|
||||
}) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Canvas(Modifier.weight(1f).aspectRatio(1f)) { drawBlastBoard(game) }
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
game.tray.forEachIndexed { i, p ->
|
||||
val chosen = i == game.selected
|
||||
val corner = RoundedCornerShape(8.dp)
|
||||
Box(Modifier.size(96.dp, 80.dp).background(if (chosen && game.inTray) NightNavy else NightPanel, corner)
|
||||
.border(if (chosen) 3.dp else 0.dp, if (chosen && game.inTray) NightYellow else if (chosen) NightMuted else Color.Transparent, corner)) {
|
||||
// The tray in the Arcade's button style: the yellow ring only where the remote is.
|
||||
Box(Modifier.size(96.dp, 80.dp).background(if (chosen && game.inTray) ArcadeColours.FocusFill else ArcadeColours.Panel, corner)
|
||||
.border(if (chosen && game.inTray) 3.dp else if (chosen) 2.dp else 1.dp, if (chosen && game.inTray) ArcadeColours.Yellow else if (chosen) ArcadeColours.Ink else ArcadeColours.Line, corner)) {
|
||||
if (p != null) Canvas(Modifier.fillMaxSize().padding(8.dp)) { drawTrayPiece(p, minOf(size.width / 5, size.height / 5)) }
|
||||
}
|
||||
}
|
||||
@@ -250,16 +277,11 @@ internal fun BlastOffScreen(play: ArcadePlay) {
|
||||
for (k in 1..6) drawCircle(Color(0xFFFFE066).copy(alpha = .8f - k * .12f), r * .16f, at + Offset(k * r * .5f, 0f))
|
||||
drawOrbChaser(at, r, OrbCharacter.Zip, OrbDir.Left, false, false, false, 0f)
|
||||
}
|
||||
if (paused || !game.alive) Column(Modifier.background(NightNavy, 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 "NO ROOM LEFT", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
if (!game.alive && newBest) CastCheer()
|
||||
if (!game.alive) Text(if (newBest) "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 = BlastGame.start(random)
|
||||
paused = false
|
||||
})
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}
|
||||
}
|
||||
if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLAST OFF · NO ROOM LEFT", "SCORE", "%,d".format(game.score),
|
||||
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title), detail = null,
|
||||
cheer = Mascot.Zip, onAgain = ::startRun, onBack = ::leave)
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Blast Off · ${"%,d".format(game.score)}",
|
||||
onResume = { guard.reset(); paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false)); startRun() }, onExit = ::leave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.classicPace
|
||||
import tv.orbit.classic.arcade.classicPanel
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.previousLine
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.PauseWhenHidden
|
||||
import tv.orbit.classic.arcade.RepeatGuard
|
||||
@@ -126,8 +144,6 @@ internal data class BlockGame(val board: List<IntArray>, val piece: BlockPiece,
|
||||
}
|
||||
}
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
/** Orbit's colours for the seven shapes: the channel palette, not anyone else's. */
|
||||
internal val BlockColours = listOf(Color(0xFF39C6F4), Color(0xFFFFD84A), Color(0xFFB36BFF), Color(0xFF6EDCAA), Color(0xFFFF6B6B), Color(0xFF4C7DFF), Color(0xFFFF9F43))
|
||||
|
||||
@@ -141,10 +157,10 @@ private fun DrawScope.cell(x: Int, y: Int, size: Float, origin: Offset, colour:
|
||||
internal fun BlockField(game: BlockGame, modifier: Modifier) = Canvas(modifier) {
|
||||
val size = minOf(this.size.width / BLOCK_COLUMNS, this.size.height / BLOCK_ROWS)
|
||||
val origin = Offset((this.size.width - size * BLOCK_COLUMNS) / 2, (this.size.height - size * BLOCK_ROWS) / 2)
|
||||
drawRect(Color(0xFF050E2A), origin, Size(size * BLOCK_COLUMNS, size * BLOCK_ROWS))
|
||||
drawRect(ArcadeColours.Night, origin, Size(size * BLOCK_COLUMNS, size * BLOCK_ROWS))
|
||||
for (y in 0 until BLOCK_ROWS) for (x in 0 until BLOCK_COLUMNS) {
|
||||
val v = game.board[y][x]
|
||||
if (v > 0) cell(x, y, size, origin, BlockColours[v - 1]) else drawRect(Color(0xFF0B1B44), Offset(origin.x + x * size + size * .45f, origin.y + y * size + size * .45f), Size(size * .1f, size * .1f))
|
||||
if (v > 0) cell(x, y, size, origin, BlockColours[v - 1]) else drawRect(ArcadeColours.Panel, Offset(origin.x + x * size + size * .45f, origin.y + y * size + size * .45f), Size(size * .1f, size * .1f))
|
||||
}
|
||||
if (game.alive) {
|
||||
game.landing().cells().forEach { (x, y) -> if (y >= 0) cell(x, y, size, origin, BlockColours[game.piece.kind], .22f) }
|
||||
@@ -163,73 +179,76 @@ private fun NextPiece(kind: Int, modifier: Modifier) = Canvas(modifier) {
|
||||
|
||||
@Composable
|
||||
internal fun BlockDropScreen(play: ArcadePlay) {
|
||||
val best = play.best
|
||||
val gameDef = ArcadeGames.Blocks
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val random = remember { java.util.Random() }
|
||||
var game by remember { mutableStateOf(BlockGame.start(random)) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
// Holding OK drops one piece, not one after another (audit finding 8).
|
||||
val guard = remember { RepeatGuard() }
|
||||
PauseWhenHidden(game.alive) { paused = true; guard.reset() }
|
||||
LaunchedEffect(paused, game.alive) {
|
||||
while (!paused && game.alive) { kotlinx.coroutines.delay(game.tickMs); game = game.fall(random = random) }
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
val pace = classicPace(play.difficulty)
|
||||
// Holding OK drops one piece (audit finding 8), and holding ▲ turns it once: a held ▲ used to spin it round and round.
|
||||
val guard = remember { RepeatGuard(setOf(ArcadeKey.Ok, ArcadeKey.Up)) }
|
||||
fun pause() { paused = true; guard.reset() }
|
||||
PauseWhenHidden(stage == ClassicStage.Play && !paused) { pause() }
|
||||
// Gravity only while playing; Difficulty sets its pace (Normal as it always was).
|
||||
LaunchedEffect(stage, paused, game.alive) {
|
||||
while (stage == ClassicStage.Play && !paused && game.alive) { kotlinx.coroutines.delay((game.tickMs / pace).toLong()); game = game.fall(random = random) }
|
||||
}
|
||||
// Every run is saved when it ends, however it ends (Arcade Stage C): game over, Leave, or the screen going away.
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false, detail = "Level ${game.level}") }
|
||||
LaunchedEffect(game.alive) { if (game.alive) run.begin() else run.end(RunEnd(game.score, finished = true, detail = "Level ${game.level}")) }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
// The best as it stood while this game was played, so the new best still shows once it's been saved; Zip and Blaze cheer it.
|
||||
val bestBefore = remember(game.alive) { best }
|
||||
val newBest = game.score > bestBefore && game.score > 0
|
||||
BackHandler { if (game.alive) paused = !paused else play.onLeave() }
|
||||
Row(Modifier.fillMaxSize().arcadeBackdrop().padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
// Releases are always noted, so the guard knows OK was let go even if the game paused meanwhile.
|
||||
if (native.action == KeyEvent.ACTION_UP) { guard.accept(native); return@onPreviewKeyEvent false }
|
||||
if (native.action != KeyEvent.ACTION_DOWN || paused || !game.alive) return@onPreviewKeyEvent false
|
||||
val next = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> game.move(-1)
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> game.move(1)
|
||||
KeyEvent.KEYCODE_DPAD_UP -> game.turn()
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> game.fall(pressed = true, random = random)
|
||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> if (guard.accept(native)) game.drop(random) else game
|
||||
fun startRun() { bestBefore = latestPlay.best; game = BlockGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.score, finished = !game.alive, detail = "Level ${game.level}")); latestPlay.onLeave() }
|
||||
LaunchedEffect(game.alive) { if (!game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true, detail = "Level ${game.level}")); stage = ClassicStage.Result } }
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { pause() }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, OrbCharacter.Drift.colour, "Stack them neatly… zzz", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
|
||||
timed = true, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "Clear several rows at once for more; every ten rows the blocks fall faster.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, pause = ::pause) { key, native ->
|
||||
// Releases are always noted, so the guard knows a key was let go even if the game paused meanwhile.
|
||||
if (native.action == KeyEvent.ACTION_UP) { guard.accept(native); return@gameKeys false }
|
||||
if (native.action != KeyEvent.ACTION_DOWN || !game.alive) return@gameKeys false
|
||||
val next = when (key) {
|
||||
ArcadeKey.Left -> game.move(-1)
|
||||
ArcadeKey.Right -> game.move(1)
|
||||
ArcadeKey.Up -> if (guard.accept(native)) game.turn() else game
|
||||
ArcadeKey.Down -> game.fall(pressed = true, random = random)
|
||||
ArcadeKey.Ok -> if (guard.accept(native)) game.drop(random) else game
|
||||
else -> null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(190.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("BLOCK DROP", color = Honey, fontFamily = Marquee, fontSize = 34.sp)
|
||||
// Drift hosts (Paul, 6 November 2026), dozing beside the board.
|
||||
Canvas(Modifier.size(54.dp)) { drawOrbChaser(center, size.minDimension * .36f, OrbCharacter.Drift, OrbDir.Down, scared = false, returning = false, blink = false, wobble = 0f, eyesShut = !game.alive) }
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("SCORE", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.score.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("BEST", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(maxOf(best, game.score).toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("LEVEL ${game.level} · ROWS ${game.lines}", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄► Move ▲ Turn", color = NightMuted, fontSize = 13.sp)
|
||||
Text("▼ Down OK Drop", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Back Pause", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight().border(2.dp, NightBlue), contentAlignment = Alignment.Center) {
|
||||
BlockField(game, Modifier.fillMaxSize().padding(6.dp))
|
||||
if (paused || !game.alive) Column(Modifier.background(NightNavy, 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 && newBest) CastCheer()
|
||||
if (!game.alive) Text(if (newBest) "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 = BlockGame.start(random)
|
||||
paused = false
|
||||
})
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}
|
||||
}
|
||||
Column(Modifier.width(130.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("NEXT", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
NextPiece(game.next, Modifier.size(110.dp).background(Color(0xFF050E2A), RoundedCornerShape(6.dp)).padding(10.dp))
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶", "Move"), Control("▲", "Turn"), Control("▼", "Down"), Control("OK", "Drop"), Control("Back", "Pause")),
|
||||
hud = {
|
||||
HudLabel("SCORE"); HudValue("%,d".format(game.score))
|
||||
HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score)))
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("LEVEL"); HudValue("${game.level}")
|
||||
HudLabel("ROWS ${game.lines}")
|
||||
Spacer(Modifier.weight(1f))
|
||||
// Drift hosts (Paul, 6 November 2026), dozing beside the board.
|
||||
Canvas(Modifier.size(56.dp)) { drawOrbChaser(center, size.minDimension * .36f, OrbCharacter.Drift, OrbDir.Down, scared = false, returning = false, blink = false, wobble = 0f, eyesShut = true) }
|
||||
},
|
||||
side = {
|
||||
HudLabel("NEXT")
|
||||
NextPiece(game.next, Modifier.size(110.dp).classicPanel().padding(12.dp))
|
||||
}) {
|
||||
BlockField(game, Modifier.fillMaxHeight().aspectRatio(BLOCK_COLUMNS / BLOCK_ROWS.toFloat()).classicPanel().padding(6.dp))
|
||||
}
|
||||
if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLOCK DROP · LEVEL ${game.level} REACHED", "SCORE", "%,d".format(game.score),
|
||||
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title),
|
||||
detail = "${game.lines} rows cleared", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave)
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Block Drop · Level ${game.level} · ${"%,d".format(game.score)}",
|
||||
onResume = { guard.reset(); paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false, detail = "Level ${game.level}")); startRun() }, onExit = ::leave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.KeyCap
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.classicPace
|
||||
import tv.orbit.classic.arcade.classicPanel
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.previousLine
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeGameLoop
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.PauseWhenHidden
|
||||
@@ -219,14 +238,11 @@ internal data class BrickGame(val paddleX: Float, val ballX: Float, val ballY: F
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
drawRect(ArcadeColours.Night, 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))
|
||||
@@ -257,75 +273,89 @@ internal fun BrickField(game: BrickGame, modifier: Modifier) = Canvas(modifier)
|
||||
|
||||
@Composable
|
||||
internal fun BrickBreakScreen(play: ArcadePlay) {
|
||||
val best = play.best
|
||||
val gameDef = ArcadeGames.Bricks
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
var game by remember { mutableStateOf(BrickGame.start()) }
|
||||
var soundsOn by remember { mutableStateOf(play.setting("sounds")) }
|
||||
LaunchedEffect(Unit) { play.audio.preload(*BrickPowerSounds.values.toIntArray()) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var held by remember { mutableIntStateOf(0) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
PauseWhenHidden(game.alive) { paused = true }
|
||||
// Every run is saved when it ends, however it ends (Arcade Stage C): game over, Leave, or the screen going away.
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
val pace = classicPace(play.difficulty)
|
||||
// A held arrow is forgotten whenever play stops (the release may never arrive): the paddle never slides on its own.
|
||||
fun pause() { paused = true; held = 0 }
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false, detail = "Wall ${game.level}") }
|
||||
LaunchedEffect(game.alive) { if (game.alive) run.begin() else run.end(RunEnd(game.score, finished = true, detail = "Wall ${game.level}")) }
|
||||
ArcadeGameLoop(loopRuns(paused, game.alive, shown = true)) { _, dt ->
|
||||
if (paused || !game.alive) return@ArcadeGameLoop
|
||||
game = game.step((dt / 1e9f).coerceAtMost(.05f), held)
|
||||
if (game.sounds.isNotEmpty()) { game.sounds.forEach { power -> BrickPowerSounds[power]?.let { play.audio.cue(it, .7f, soundsOn) } }; game = game.copy(sounds = emptyList()) }
|
||||
fun startRun() { bestBefore = latestPlay.best; game = BrickGame.start(); held = 0; run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.score, finished = !game.alive, detail = "Wall ${game.level}")); latestPlay.onLeave() }
|
||||
PauseWhenHidden(stage == ClassicStage.Play && !paused) { pause() }
|
||||
ArcadeGameLoop(loopRuns(paused, game.alive && stage == ClassicStage.Play, shown = true)) { _, dt ->
|
||||
if (paused || !game.alive || stage != ClassicStage.Play) return@ArcadeGameLoop
|
||||
// Difficulty runs the whole wall a little slower or quicker; Normal is as it always was.
|
||||
game = game.step((dt / 1e9f).coerceAtMost(.05f) * pace, held)
|
||||
if (game.sounds.isNotEmpty()) { game.sounds.forEach { power -> BrickPowerSounds[power]?.let { latestPlay.audio.cue(it, .7f, soundsOn) } }; game = game.copy(sounds = emptyList()) }
|
||||
if (!game.alive) { held = 0; run.end(RunEnd(game.score, finished = true, detail = "Wall ${game.level}")); stage = ClassicStage.Result }
|
||||
}
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
// The best as it stood while this game was played, so the new best still shows once it's been saved; Zip and Blaze cheer it.
|
||||
val bestBefore = remember(game.alive) { best }
|
||||
val newBest = game.score > bestBefore && game.score > 0
|
||||
BackHandler { if (game.alive) paused = !paused else play.onLeave() }
|
||||
Row(Modifier.fillMaxSize().arcadeBackdrop().padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (paused || !game.alive) return@onPreviewKeyEvent false
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { pause() }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, OrbCharacter.Luna.colour, "Keep me bouncing!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
|
||||
timed = true, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "About one brick in ten drops a gold star: catch it for one of the cast's powers.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, pause = ::pause) { key, native ->
|
||||
val down = native.action == KeyEvent.ACTION_DOWN
|
||||
when (native.keyCode) {
|
||||
when (key) {
|
||||
// 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 }
|
||||
ArcadeKey.Left -> { held = if (down) -1 else if (held == -1) 0 else held; true }
|
||||
ArcadeKey.Right -> { held = if (down) 1 else if (held == 1) 0 else held; true }
|
||||
ArcadeKey.Ok -> { 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 = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.score.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("BEST", color = NightMuted, 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 = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold)
|
||||
// What's helping right now.
|
||||
listOfNotNull(BrickPower.DoubleLuna.takeIf { game.extra.isNotEmpty() }, BrickPower.BlazeRun.takeIf { game.blazeAt >= 0f }, BrickPower.DriftNet.takeIf { game.net },
|
||||
BrickPower.ZipSplit.takeIf { game.volleys > 0 || game.sparks.isNotEmpty() }, BrickPower.WideOrbit.takeIf { game.wideFor > 0f })
|
||||
.forEach { Text(it.title.uppercase(), color = Honey, fontSize = 13.sp, fontWeight = FontWeight.SemiBold) }
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄► Hold to move", color = NightMuted, fontSize = 13.sp)
|
||||
Text("OK Launch Back Pause", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Catch the gold stars", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight().border(2.dp, NightBlue), 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(NightNavy, 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 && newBest) CastCheer()
|
||||
if (!game.alive) Text(if (newBest) "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("Sounds: ${if (soundsOn) "On" else "Off"}", Modifier.width(200.dp), onClick = { soundsOn = !soundsOn; play.setSetting("sounds", soundsOn) })
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶", "Hold to move"), Control("OK", "Launch"), Control("Back", "Pause")),
|
||||
note = "Catch the gold stars", hud = {
|
||||
HudLabel("SCORE"); HudValue("%,d".format(game.score))
|
||||
HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score)))
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("WALL ${game.level}")
|
||||
HudLabel("BALLS ${game.lives}")
|
||||
Spacer(Modifier.height(6.dp))
|
||||
// What's helping right now.
|
||||
HudLabel("POWERS")
|
||||
var any = false
|
||||
if (game.extra.isNotEmpty()) { any = true; PowerLine(BrickPower.DoubleLuna) }
|
||||
if (game.blazeAt >= 0f) { any = true; PowerLine(BrickPower.BlazeRun) }
|
||||
if (game.net) { any = true; PowerLine(BrickPower.DriftNet) }
|
||||
if (game.volleys > 0 || game.sparks.isNotEmpty()) { any = true; PowerLine(BrickPower.ZipSplit) }
|
||||
if (game.wideFor > 0f) { any = true; PowerLine(BrickPower.WideOrbit) }
|
||||
if (!any) Text("None yet", color = ArcadeColours.Muted, fontSize = 14.sp)
|
||||
}) {
|
||||
Box(Modifier.fillMaxSize().classicPanel().padding(6.dp), contentAlignment = Alignment.Center) {
|
||||
BrickField(game, Modifier.fillMaxSize())
|
||||
if (game.alive && !game.launched && !paused) Row(Modifier.align(Alignment.BottomCenter).padding(bottom = 40.dp), verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)) { KeyCap("OK"); Text("Launch Luna", color = ArcadeColours.Yellow, fontSize = 16.sp, fontWeight = FontWeight.SemiBold) }
|
||||
}
|
||||
}
|
||||
if (stage == ClassicStage.Result) ClassicResult(gameDef, "BRICK BREAK · WALL ${game.level} REACHED", "SCORE", "%,d".format(game.score),
|
||||
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title),
|
||||
detail = "${game.bricks.size} bricks were left in wall ${game.level}", cheer = Mascot.Blaze, onAgain = ::startRun, onBack = ::leave)
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Brick Break · Wall ${game.level} · ${"%,d".format(game.score)}",
|
||||
onResume = { held = 0; paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false, detail = "Wall ${game.level}")); startRun() }, onExit = ::leave,
|
||||
sound = if (soundsOn) "On" else "Off", onSound = { soundsOn = !soundsOn; latestPlay.setSetting("sounds", soundsOn) })
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PowerLine(p: BrickPower) = Text(p.title, color = ArcadeColours.Yellow, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
|
||||
|
||||
/** Each power's short sound, made for Orbit (design/arcade/build-power-sounds.py); quiet, and played through the Arcade's one sound service. */
|
||||
internal val BrickPowerSounds = mapOf(BrickPower.DoubleLuna to R.raw.power_double_luna, BrickPower.BlazeRun to R.raw.power_blaze_run, BrickPower.DriftNet to R.raw.power_drift_net,
|
||||
BrickPower.ZipSplit to R.raw.power_zip_split, BrickPower.WideOrbit to R.raw.power_wide_orbit)
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGameLoop
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.classicPace
|
||||
import tv.orbit.classic.arcade.classicPanel
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.previousLine
|
||||
import tv.orbit.classic.arcade.PauseWhenHidden
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.loopRuns
|
||||
@@ -50,19 +66,23 @@ import kotlin.math.sin
|
||||
*/
|
||||
internal const val ORB_TICK_MS = 20L
|
||||
|
||||
/** The maze's left half and middle column; the right half mirrors it. # wall, . star, o power hexagon, - the den door, H their den, P start. */
|
||||
/**
|
||||
* The maze's left half and middle column; the right half mirrors it. # wall, . star, o power hexagon, - the den door, H their den, P start.
|
||||
* Redrawn 9 November 2026 (Paul: "weird pillars or dots seem separate from the maze"): the same corridors and den, with no
|
||||
* wall standing on its own, no dead ends, and the walls in solid blocks.
|
||||
*/
|
||||
private val OrbMazeLeft = listOf(
|
||||
"############",
|
||||
"#o.........#",
|
||||
"#.###.####.#",
|
||||
"#.###.####..",
|
||||
"#...........",
|
||||
"#.###.#.#...",
|
||||
"#.....#..##-",
|
||||
"...#..#..#HH",
|
||||
"#.#...#..###",
|
||||
"#.##.##.###-",
|
||||
"..##....##HH",
|
||||
"#.#...#.####",
|
||||
"#.#.###.....",
|
||||
"#...#...##.#",
|
||||
"#.###.#.##..",
|
||||
"#...#...###.",
|
||||
"#.###.#.....",
|
||||
"#o....#....P",
|
||||
"############")
|
||||
|
||||
@@ -80,6 +100,9 @@ internal class OrbMaze(val rows: List<String> = OrbMazeRows) {
|
||||
val height = rows.size
|
||||
private fun at(x: Int, y: Int) = rows.getOrNull(y)?.getOrNull(Math.floorMod(x, width)) ?: '#'
|
||||
fun wall(p: OrbPos) = at(p.x, p.y) == '#'
|
||||
/** The walls, square by square, made once: the drawing reads this, so it makes nothing new each frame. */
|
||||
val walls = BooleanArray(width * height) { i -> rows[i / width][i % width] == '#' }
|
||||
fun wallAt(x: Int, y: Int) = x in 0 until width && y in 0 until height && walls[y * width + x]
|
||||
fun door(p: OrbPos) = at(p.x, p.y) == '-'
|
||||
fun den(p: OrbPos) = at(p.x, p.y) == 'H'
|
||||
/** One step on, through the side tunnels where a row is open at both ends. */
|
||||
@@ -233,9 +256,7 @@ internal data class OrbGame(
|
||||
}
|
||||
}
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
private val OrbWall = Color(0xFF2E4FE0)
|
||||
private val OrbWallFill = Color(0xFF1B2F8F)
|
||||
private val OrbWallLight = Color(0xFF7D95FF)
|
||||
private val OrbFloor = Color(0xFF0A1850)
|
||||
private val OrbStar = Color(0xFFFFE066)
|
||||
@@ -376,38 +397,45 @@ internal fun DrawScope.drawOrbBee(centre: Offset, r: Float, flap: Float = 0f) {
|
||||
for (side in listOf(-1f, 1f)) { drawCircle(Color.White, 6.2f * k, centre + Offset(side * 8 * k, -4 * k)); drawCircle(navy, 3.1f * k, centre + Offset(side * 8 * k + 1.5f * k, -4 * k)) }
|
||||
}
|
||||
|
||||
/** The maze and everyone in it. [phase] is how far between ticks we are, for smooth movement; [glow] the power glow, 0 to 1. */
|
||||
internal fun DrawScope.drawOrbField(game: OrbGame, phase: Float = 0f, glow: Float = 0f, timeMs: Long = 0L) {
|
||||
/** One hexagon, made once and reused for every power hexagon, every frame. */
|
||||
private val orbHex by lazy { Path() }
|
||||
|
||||
/**
|
||||
* The maze and everyone in it. [phase] is how far between ticks we are, for smooth movement; [glow] the power glow, 0 to 1.
|
||||
* [steady] (Reduce flashing) keeps the frightened cast from blinking as the power wears off.
|
||||
*/
|
||||
internal fun DrawScope.drawOrbField(game: OrbGame, phase: Float = 0f, glow: Float = 0f, timeMs: Long = 0L, steady: Boolean = false) {
|
||||
val maze = game.maze
|
||||
val cell = minOf(size.width / maze.width, size.height / maze.height)
|
||||
val origin = Offset((size.width - cell * maze.width) / 2, (size.height - cell * maze.height) / 2)
|
||||
fun centre(p: OrbPos) = origin + Offset((p.x + .5f) * cell, (p.y + .5f) * cell)
|
||||
drawRect(OrbFloor, origin, Size(cell * maze.width, cell * maze.height))
|
||||
// A faint check in the floor.
|
||||
for (y in 0 until maze.height) for (x in 0 until maze.width) if ((x + y) % 2 == 0) drawRect(Color.White.copy(alpha = .025f), origin + Offset(x * cell, y * cell), Size(cell, cell))
|
||||
if (glow > 0f) drawRect(Brush.radialGradient(listOf(Color(0xFF6EF0FF).copy(alpha = .28f * glow), Color(0xFF6EF0FF).copy(alpha = .06f * glow)),
|
||||
centre(game.player.pos), maxOf(size.width, size.height) * .7f), origin, Size(cell * maze.width, cell * maze.height))
|
||||
// Walls as glowing pipes: a joint on every wall square, joined to its neighbours.
|
||||
val walls = (0 until maze.height).flatMap { y -> (0 until maze.width).map { x -> OrbPos(x, y) } }.filter { maze.wall(it) }
|
||||
val wallColour = if (glow > 0f) androidx.compose.ui.graphics.lerp(OrbWall, Color(0xFF29C4E8), glow * .6f) else OrbWall
|
||||
for ((width, colour) in listOf(cell * .46f to wallColour, cell * .16f to OrbWallLight)) for (w in walls) {
|
||||
val c = centre(w)
|
||||
drawCircle(colour, width / 2, c)
|
||||
for (d in listOf(OrbDir.Right, OrbDir.Down)) {
|
||||
val n = OrbPos(w.x + d.dx, w.y + d.dy)
|
||||
if (n.x < maze.width && n.y < maze.height && maze.wall(n)) drawLine(colour, c, centre(n), width)
|
||||
}
|
||||
// Walls as solid blocks with a bright edge wherever they face a corridor, so every wall reads as part of the maze.
|
||||
val fill = if (glow > 0f) androidx.compose.ui.graphics.lerp(OrbWallFill, Color(0xFF0E5A78), glow * .6f) else OrbWallFill
|
||||
val edge = if (glow > 0f) androidx.compose.ui.graphics.lerp(OrbWallLight, Color(0xFF7FF3FF), glow * .6f) else OrbWallLight
|
||||
val line = cell * .09f; val inset = cell * .08f
|
||||
for (y in 0 until maze.height) for (x in 0 until maze.width) {
|
||||
if (!maze.wallAt(x, y)) continue
|
||||
val l = origin.x + x * cell; val t = origin.y + y * cell
|
||||
drawRect(fill, Offset(l, t), Size(cell + .5f, cell + .5f))
|
||||
if (y > 0 && !maze.wallAt(x, y - 1)) drawLine(edge, Offset(l, t + inset), Offset(l + cell, t + inset), line)
|
||||
if (y < maze.height - 1 && !maze.wallAt(x, y + 1)) drawLine(edge, Offset(l, t + cell - inset), Offset(l + cell, t + cell - inset), line)
|
||||
if (x > 0 && !maze.wallAt(x - 1, y)) drawLine(edge, Offset(l + inset, t), Offset(l + inset, t + cell), line)
|
||||
if (x < maze.width - 1 && !maze.wallAt(x + 1, y)) drawLine(edge, Offset(l + cell - inset, t), Offset(l + cell - inset, t + cell), line)
|
||||
}
|
||||
drawLine(Color(0xFFFF9BD0), centre(maze.doorCell) - Offset(cell * .45f, 0f), centre(maze.doorCell) + Offset(cell * .45f, 0f), cell * .12f)
|
||||
for (s in game.stars) drawCircle(OrbStar, cell * .1f, centre(s))
|
||||
// The power hexagons pulse gently through Orbit's colours.
|
||||
val pulse = .85f + .15f * sin(timeMs / 260.0).toFloat()
|
||||
game.powers.forEachIndexed { i, p ->
|
||||
val hex = Path().apply {
|
||||
for (k in 0..5) { val a = Math.toRadians(60.0 * k + 30); val at = centre(p) + Offset((cell * .32f * pulse * kotlin.math.cos(a)).toFloat(), (cell * .32f * pulse * sin(a)).toFloat()); if (k == 0) moveTo(at.x, at.y) else lineTo(at.x, at.y) }
|
||||
close()
|
||||
}
|
||||
drawPath(hex, listOf(Color(0xFF6EF0FF), Color(0xFFFF7AC6), Color(0xFFB79BFF), Color(0xFF7DFFB0))[i % 4])
|
||||
for (s in game.stars) { val c = centre(s); drawCircle(OrbStar.copy(alpha = .22f), cell * .24f, c); drawCircle(OrbStar, cell * .14f, c) }
|
||||
// The power hexagons pulse gently through Orbit's colours (still with Reduce motion or flashing).
|
||||
val pulse = if (steady) 1f else .85f + .15f * sin(timeMs / 260.0).toFloat()
|
||||
var i = 0
|
||||
for (p in game.powers) {
|
||||
val hex = orbHex; hex.reset()
|
||||
val c = centre(p)
|
||||
for (k in 0..5) { val a = Math.toRadians(60.0 * k + 30); val x = c.x + (cell * .34f * pulse * kotlin.math.cos(a)).toFloat(); val y = c.y + (cell * .34f * pulse * sin(a)).toFloat(); if (k == 0) hex.moveTo(x, y) else hex.lineTo(x, y) }
|
||||
hex.close()
|
||||
drawPath(hex, OrbPowerColours[i % 4]); i++
|
||||
}
|
||||
fun drawn(m: OrbMover, every: Int): Offset {
|
||||
val a = centre(m.from); val b = centre(m.pos)
|
||||
@@ -415,15 +443,18 @@ internal fun DrawScope.drawOrbField(game: OrbGame, phase: Float = 0f, glow: Floa
|
||||
val f = ((game.tick - m.movedAt + phase) / every).coerceIn(0f, 1f)
|
||||
return a + (b - a) * f
|
||||
}
|
||||
val blinking = game.powered && game.powerLeft < 100 && (game.powerLeft / 12) % 2 == 0
|
||||
game.chasers.forEachIndexed { i, c ->
|
||||
val blinking = !steady && game.powered && game.powerLeft < 100 && (game.powerLeft / 12) % 2 == 0
|
||||
for (n in game.chasers.indices) {
|
||||
val c = game.chasers[n]
|
||||
val every = when { c.returning -> 4; c.scared -> game.chaserEvery + 6; !c.out -> game.chaserEvery + 4; else -> game.chaserEvery }
|
||||
drawOrbChaser(drawn(c.mover, every), cell * .42f, OrbCharacter.entries[i], c.mover.dir, c.scared, c.returning, blinking, timeMs / 140f + i)
|
||||
drawOrbChaser(drawn(c.mover, every), cell * .42f, OrbCharacter.entries[n], c.mover.dir, c.scared, c.returning, blinking, timeMs / 140f + n)
|
||||
}
|
||||
val chomp = if (game.readyLeft > 0) 0f else (.5f + .5f * sin(timeMs / 70.0).toFloat())
|
||||
drawOrbMascot(drawn(game.player, game.playerEvery), cell * .38f, game.player.dir, chomp)
|
||||
}
|
||||
|
||||
private val OrbPowerColours = listOf(Color(0xFF6EF0FF), Color(0xFFFF7AC6), Color(0xFFB79BFF), Color(0xFF7DFFB0))
|
||||
|
||||
/** Short sounds made on the box itself, quiet and original: a pip for each star, a rising swell for power, and so on. */
|
||||
private class OrbSounds {
|
||||
private val rate = 22_050
|
||||
@@ -457,95 +488,100 @@ private class OrbSounds {
|
||||
|
||||
@Composable
|
||||
internal fun OrbManScreen(play: ArcadePlay) {
|
||||
val best = play.best
|
||||
val gameDef = ArcadeGames.OrbMan
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val calm = Motion.reduce
|
||||
val steady = calm || play.reduceFlashing
|
||||
var soundOn by remember { mutableStateOf(play.setting("sound")) }
|
||||
val sounds = remember { OrbSounds() }
|
||||
DisposableEffect(Unit) { onDispose { sounds.release() } }
|
||||
val random = remember { java.util.Random() }
|
||||
var game by remember { mutableStateOf(OrbGame.start()) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var phase by remember { mutableFloatStateOf(0f) }
|
||||
var clock by remember { mutableLongStateOf(0L) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
PauseWhenHidden(game.alive) { paused = true }
|
||||
// Every run is saved when it ends, however it ends (Arcade Stage C): game over, Leave, or the screen going away.
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
// Difficulty: Normal is the game as it always was; Gentle a fifth slower, Tricky a fifth quicker.
|
||||
val tickMs = ORB_TICK_MS / classicPace(play.difficulty)
|
||||
// Every run is saved when it ends, however it ends: game over, Leave, or the screen going away.
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false, detail = "Level ${game.level}") }
|
||||
LaunchedEffect(game.alive) { if (game.alive) run.begin() else run.end(RunEnd(game.score, finished = true, detail = "Level ${game.level}")) }
|
||||
fun startRun() { bestBefore = latestPlay.best; game = OrbGame.start(); run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.score, finished = !game.alive, detail = "Level ${game.level}")); latestPlay.onLeave() }
|
||||
PauseWhenHidden(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
// One frame clock: whole ticks move the game, what's left over places everyone smoothly in between.
|
||||
var carry by remember { mutableLongStateOf(0L) }
|
||||
ArcadeGameLoop(loopRuns(paused, game.alive, shown = true), onStart = { carry = 0L; phase = 0f }) { now, dt ->
|
||||
if (paused || !game.alive) return@ArcadeGameLoop
|
||||
val ms = now / 1_000_000
|
||||
carry += (ms - (now - dt) / 1_000_000).coerceAtMost(100)
|
||||
clock = ms
|
||||
var carry by remember { mutableFloatStateOf(0f) }
|
||||
ArcadeGameLoop(loopRuns(paused, game.alive && stage == ClassicStage.Play, shown = true), onStart = { carry = 0f; phase = 0f }) { now, dt ->
|
||||
if (paused || !game.alive || stage != ClassicStage.Play) return@ArcadeGameLoop
|
||||
carry += (dt / 1_000_000f).coerceAtMost(100f)
|
||||
clock = now / 1_000_000
|
||||
var g = game
|
||||
val level = play.audio.effects(1f, soundOn)
|
||||
while (carry >= ORB_TICK_MS) {
|
||||
carry -= ORB_TICK_MS
|
||||
val level = latestPlay.audio.effects(1f, soundOn)
|
||||
while (carry >= tickMs) {
|
||||
carry -= tickMs
|
||||
g = g.step(random)
|
||||
if (level > 0f) g.events.forEach { sounds.play(it, level) }
|
||||
if (!g.alive) break
|
||||
}
|
||||
game = g
|
||||
phase = carry.toFloat() / ORB_TICK_MS
|
||||
phase = carry / tickMs
|
||||
if (!g.alive) { run.end(RunEnd(g.score, finished = true, detail = "Level ${g.level}")); stage = ClassicStage.Result }
|
||||
}
|
||||
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
// The best as it stood while this game was played, so the new best still shows once it's been saved; Zip and Blaze cheer it.
|
||||
val bestBefore = remember(game.alive) { best }
|
||||
val newBest = game.score > bestBefore && game.score > 0
|
||||
BackHandler { if (game.alive) paused = !paused else play.onLeave() }
|
||||
// The power glow breathes gently; with Reduce motion on it holds steady.
|
||||
val glow = if (!game.powered) 0f else if (calm) .7f else .55f + .25f * sin(clock / 400.0).toFloat()
|
||||
Row(Modifier.fillMaxSize().arcadeBackdrop().padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (native.action != KeyEvent.ACTION_DOWN || paused || !game.alive) return@onPreviewKeyEvent false
|
||||
val dir = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_UP -> OrbDir.Up; KeyEvent.KEYCODE_DPAD_DOWN -> OrbDir.Down
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> OrbDir.Left; KeyEvent.KEYCODE_DPAD_RIGHT -> OrbDir.Right
|
||||
else -> null
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, OrbCharacter.Blaze.colour, "Help me clear the stars!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
|
||||
timed = true, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "Ollie keeps going on his own: press an arrow and he turns at the next gap.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
// The power glow breathes gently; with Reduce motion or flashing it holds steady.
|
||||
val glow = if (!game.powered) 0f else if (steady) .7f else .55f + .25f * sin(clock / 400.0).toFloat()
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, pause = { paused = true }) { key, native ->
|
||||
if (native.action != KeyEvent.ACTION_DOWN) return@gameKeys key != ArcadeKey.Other
|
||||
when (key) {
|
||||
ArcadeKey.Up -> { game = game.turn(OrbDir.Up); true }
|
||||
ArcadeKey.Down -> { game = game.turn(OrbDir.Down); true }
|
||||
ArcadeKey.Left -> { game = game.turn(OrbDir.Left); true }
|
||||
ArcadeKey.Right -> { game = game.turn(OrbDir.Right); true }
|
||||
ArcadeKey.Ok -> { if (native.repeatCount == 0) paused = true; true }
|
||||
else -> false
|
||||
}
|
||||
if (dir != null) game = game.turn(dir)
|
||||
if (native.keyCode == KeyEvent.KEYCODE_DPAD_CENTER || native.keyCode == KeyEvent.KEYCODE_ENTER) { paused = true; return@onPreviewKeyEvent true }
|
||||
dir != null
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(170.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("STAR CHASE", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("SCORE", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.score.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("BEST", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(maxOf(best, game.score).toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("LEVEL ${game.level}", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Canvas(Modifier.height(30.dp).fillMaxWidth()) { repeat(game.lives) { drawOrbMascot(Offset(16f + it * 44f, size.height / 2), 11f) } }
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Text("THE CAST", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
OrbCharacter.entries.forEach { who ->
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Canvas(Modifier.size(22.dp)) { drawOrbChaser(center, size.minDimension * .4f, who, OrbDir.Right, false, false, false, 0f) }
|
||||
Text(who.title, color = who.colour, fontSize = 14.sp, fontWeight = FontWeight.SemiBold)
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶▲▼", "Steer Ollie"), Control("OK", "Pause"), Control("Back", "Pause")),
|
||||
note = "He keeps moving: turn before the gap", hud = {
|
||||
HudLabel("SCORE"); HudValue("%,d".format(game.score))
|
||||
HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score)))
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("LEVEL ${game.level}")
|
||||
Canvas(Modifier.height(30.dp).fillMaxWidth()) { val r = size.height * .36f; for (k in 0 until game.lives) drawOrbMascot(Offset(r * 1.6f + k * r * 3.6f, size.height / 2), r) }
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("THE CAST")
|
||||
OrbCharacter.entries.forEach { who ->
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Canvas(Modifier.size(22.dp)) { drawOrbChaser(center, size.minDimension * .4f, who, OrbDir.Right, false, false, false, 0f) }
|
||||
Text(who.title, color = who.colour, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄►▲▼ Steer", color = NightMuted, fontSize = 13.sp)
|
||||
Text("OK or Back Pause", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
|
||||
Canvas(Modifier.fillMaxSize()) { drawOrbField(game, phase, glow, clock) }
|
||||
if (game.alive && game.readyLeft > 0 && !paused) Text(if (game.tick == 0 && game.level == 1) "READY!" else if (game.score > 0 && game.stars.size + game.powers.size == game.maze.cells('.').size + game.maze.cells('o').size) "LEVEL ${game.level}" else "READY!",
|
||||
Modifier.background(NightNavy.copy(alpha = .8f), RoundedCornerShape(6.dp)).padding(horizontal = 16.dp, vertical = 6.dp), color = Honey, fontFamily = Marquee, fontSize = 26.sp)
|
||||
if (paused || !game.alive) Column(Modifier.background(NightNavy, 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 && newBest) CastCheer()
|
||||
if (!game.alive) Text(if (newBest) "New best: ${game.score}" else "Score: ${game.score} · level ${game.level}", 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 = OrbGame.start()
|
||||
paused = false
|
||||
})
|
||||
OrbitButton("Sound: ${if (soundOn) "On" else "Off"}", Modifier.width(200.dp), onClick = { soundOn = !soundOn; play.setSetting("sound", soundOn) })
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}) {
|
||||
Box(Modifier.fillMaxSize().classicPanel().padding(8.dp), contentAlignment = Alignment.Center) {
|
||||
Canvas(Modifier.fillMaxSize()) { drawOrbField(game, phase, glow, clock, steady) }
|
||||
if (game.alive && game.readyLeft > 0 && !paused) Text(if (game.tick == 0 && game.level == 1) "READY!" else if (game.score > 0 && game.stars.size + game.powers.size == game.maze.cells('.').size + game.maze.cells('o').size) "LEVEL ${game.level}" else "READY!",
|
||||
Modifier.background(ArcadeColours.PanelDeep.copy(alpha = .9f), RoundedCornerShape(8.dp)).padding(horizontal = 16.dp, vertical = 6.dp), color = ArcadeColours.Yellow, fontFamily = Anton, fontSize = 26.sp)
|
||||
}
|
||||
}
|
||||
if (stage == ClassicStage.Result) ClassicResult(gameDef, "STAR CHASE · LEVEL ${game.level} REACHED", "SCORE", "%,d".format(game.score),
|
||||
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title),
|
||||
detail = "${game.maze.cells('.').size + game.maze.cells('o').size - game.stars.size - game.powers.size} stars left on level ${game.level}".takeIf { game.stars.isNotEmpty() },
|
||||
cheer = tv.orbit.classic.arcade.Mascot.Zip, onAgain = ::startRun, onBack = ::leave)
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Star Chase · Level ${game.level} · ${"%,d".format(game.score)}",
|
||||
onResume = { paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false, detail = "Level ${game.level}")); startRun() }, onExit = ::leave,
|
||||
sound = if (soundOn) "On" else "Off", onSound = { soundOn = !soundOn; latestPlay.setSetting("sound", soundOn) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,21 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.classicPanel
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.SessionEvent
|
||||
@@ -78,97 +92,95 @@ internal data class PairsGame(val cards: List<Int>, val matched: Set<Int> = empt
|
||||
*/
|
||||
private val PairsChannels = listOf(101, 201, 301, 401, 601, 612, 0, 1, 2, 4)
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
|
||||
@Composable
|
||||
private fun PairsCard(channel: Int, up: Boolean, matched: Boolean, selected: Boolean, modifier: Modifier) {
|
||||
// Reduce motion: the card shows its face at once instead of turning over.
|
||||
val turn by animateFloatAsState(if (up) 1f else 0f, tween(if (Motion.reduce) 0 else 260), label = "turn")
|
||||
Box(modifier.graphicsLayer { rotationY = 180f * (1 - turn); cameraDistance = 12 * density }
|
||||
.background(if (turn > .5f) Color(0xFF0B1B44) else NightPanel, RoundedCornerShape(8.dp))
|
||||
.border(if (selected) 3.dp else 1.dp, if (selected) NightYellow else if (matched) Honey else NightBlue, RoundedCornerShape(8.dp)), contentAlignment = Alignment.Center) {
|
||||
.background(if (turn > .5f) ArcadeColours.PanelDeep else if (selected) ArcadeColours.FocusFill else ArcadeColours.Panel, RoundedCornerShape(8.dp))
|
||||
.border(if (selected) 3.dp else 1.dp, if (selected) ArcadeColours.Yellow else if (matched) ArcadeColours.Green else ArcadeColours.Line, RoundedCornerShape(8.dp)), contentAlignment = Alignment.Center) {
|
||||
if (turn > .5f && channel < 100) androidx.compose.foundation.Canvas(Modifier.fillMaxSize().padding(8.dp).alpha(if (matched) .7f else 1f)) {
|
||||
val r = size.minDimension * .36f
|
||||
if (channel == 0) drawOrbMascot(center, r * .8f)
|
||||
else drawOrbChaser(center, r, OrbCharacter.entries[channel - 1], OrbDir.Down, scared = false, returning = false, blink = false, wobble = 0f)
|
||||
}
|
||||
else if (turn > .5f) ChannelBrands.forNumber(channel)?.let { Image(cachedPainter(it.logo), it.displayName, Modifier.fillMaxSize().padding(10.dp).alpha(if (matched) .7f else 1f)) }
|
||||
else Text("O", color = NightMuted.copy(alpha = .5f), fontFamily = Marquee, fontSize = 26.sp)
|
||||
// The card back: Orbit's own ring, gold on navy, with a star at its heart.
|
||||
else androidx.compose.foundation.Canvas(Modifier.fillMaxSize().padding(10.dp)) {
|
||||
val r = size.minDimension * .34f
|
||||
drawOval(ArcadeColours.Yellow.copy(alpha = .75f), center - androidx.compose.ui.geometry.Offset(r * 1.5f, r * .45f), androidx.compose.ui.geometry.Size(r * 3f, r * .9f), style = androidx.compose.ui.graphics.drawscope.Stroke(r * .14f))
|
||||
drawCircle(ArcadeColours.Line, r * .62f, center)
|
||||
drawPath(starPath(center, r * .42f, r * .18f, 0f), ArcadeColours.Yellow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun PairsScreen(play: ArcadePlay) {
|
||||
val best = play.best
|
||||
val gameDef = ArcadeGames.Pairs
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val random = remember { java.util.Random() }
|
||||
var game by remember { mutableStateOf(PairsGame.deal(random)) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
// The shared pause (Arcade Stage C): Back pauses instead of leaving at once.
|
||||
var session by remember { mutableStateOf<SessionState>(SessionState.Play) }
|
||||
LaunchedEffect(session) { if (session == SessionState.Exited) play.onLeave() else if (session == SessionState.Play && !game.done) runCatching { focus.requestFocus() } }
|
||||
LaunchedEffect(game.waiting) { if (game.waiting) { delay(900); game = game.hide() } }
|
||||
var newBest by remember { mutableStateOf(false) }
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
LaunchedEffect(game.waiting, paused) { if (game.waiting && !paused) { delay(900); game = game.hide() } }
|
||||
// A cleared board is saved for this profile; leaving part-way saves nothing (fewest moves only counts when it's done).
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.moves, finished = game.done) }
|
||||
LaunchedEffect(game.done) {
|
||||
if (game.done) {
|
||||
newBest = best == 0 || game.moves < best
|
||||
run.end(RunEnd(game.moves, finished = true))
|
||||
session = reduceSession(session, SessionEvent.Finish(RunEnd(game.moves, true), newBest))
|
||||
menuFocus.requestFocus()
|
||||
} else { run.begin(); focus.requestFocus() }
|
||||
fun deal() { bestBefore = latestPlay.best; game = PairsGame.deal(random); run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.moves, finished = game.done)); latestPlay.onLeave() }
|
||||
LaunchedEffect(game.done) { if (game.done && stage == ClassicStage.Play) { run.end(RunEnd(game.moves, finished = true)); stage = ClassicStage.Result } }
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
// A turned card can't be turned back, so Back always pauses here.
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, ArcadeColours.Cyan, "Remember where we are!", listOf("Your best" to if (play.best > 0) "${play.best} moves" else "Not played yet"),
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, onPlay = ::deal, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "Two cards are one move. The fewer moves, the better.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, pause = { paused = true }) { key, native ->
|
||||
if (native.action != KeyEvent.ACTION_DOWN || game.done) return@gameKeys key != ArcadeKey.Other
|
||||
val next = when (key) {
|
||||
ArcadeKey.Left -> game.moveCursor(-1, 0)
|
||||
ArcadeKey.Right -> game.moveCursor(1, 0)
|
||||
ArcadeKey.Up -> game.moveCursor(0, -1)
|
||||
ArcadeKey.Down -> game.moveCursor(0, 1)
|
||||
ArcadeKey.Ok -> if (native.repeatCount > 0) game else game.flip()
|
||||
else -> null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}
|
||||
BackHandler(session == SessionState.Play || session is SessionState.Result) { session = reduceSession(session, SessionEvent.Back) }
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Row(Modifier.fillMaxSize().arcadeBackdrop().padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (native.action != KeyEvent.ACTION_DOWN || game.done || session != SessionState.Play) return@onPreviewKeyEvent false
|
||||
val next = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> game.moveCursor(-1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> game.moveCursor(1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_UP -> game.moveCursor(0, -1)
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> game.moveCursor(0, 1)
|
||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> game.flip()
|
||||
else -> null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(190.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("PAIRS", color = Honey, fontFamily = Marquee, fontSize = 40.sp)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("MOVES", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.moves.toString(), color = Color.White, fontFamily = Marquee, fontSize = 36.sp)
|
||||
Text("BEST", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(if (best == 0) "–" else best.toString(), color = Color.White, fontFamily = Marquee, fontSize = 36.sp)
|
||||
Text("PAIRS ${game.matched.size / 2} OF ${game.cards.size / 2}", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄►▲▼ Move OK Turn", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Back Pause", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
for (row in 0 until PAIRS_ROWS) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
for (col in 0 until PAIRS_COLUMNS) {
|
||||
val i = row * PAIRS_COLUMNS + col
|
||||
PairsCard(PairsChannels[game.cards[i]], i in game.matched || i in game.open, i in game.matched, i == game.cursor && !game.done, Modifier.width(120.dp).height(76.dp))
|
||||
}
|
||||
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶▲▼", "Move"), Control("OK", "Turn a card"), Control("Back", "Pause")), hud = {
|
||||
HudLabel("MOVES"); HudValue("${game.moves}")
|
||||
HudLabel("BEST"); HudValue(if (bestBefore == 0) "—" else "$bestBefore")
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("PAIRS"); HudValue("${game.matched.size / 2} of ${game.cards.size / 2}")
|
||||
}) {
|
||||
Column(Modifier.classicPanel().padding(14.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
for (row in 0 until PAIRS_ROWS) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
for (col in 0 until PAIRS_COLUMNS) {
|
||||
val i = row * PAIRS_COLUMNS + col
|
||||
PairsCard(PairsChannels[game.cards[i]], i in game.matched || i in game.open, i in game.matched, i == game.cursor && !game.done, Modifier.width(120.dp).height(80.dp))
|
||||
}
|
||||
}
|
||||
if (game.done) Column(Modifier.background(NightNavy, RoundedCornerShape(6.dp)).border(2.dp, Honey, RoundedCornerShape(6.dp)).padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text("ALL PAIRED", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
if (newBest) CastCheer()
|
||||
Text(if (newBest) "New best: ${game.moves} moves" else "${game.moves} moves", color = Color.White, fontSize = 16.sp)
|
||||
OrbitButton("Play again", Modifier.width(200.dp).focusRequester(menuFocus), onClick = { game = PairsGame.deal(random); session = reduceSession(session, SessionEvent.PlayAgain) })
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (session is SessionState.Pause) ArcadePauseMenu(ArcadeGames.Pairs, "Pairs · ${game.moves} moves · ${game.matched.size / 2} of ${game.cards.size / 2} pairs",
|
||||
onResume = { session = reduceSession(session, SessionEvent.Resume) },
|
||||
onRestart = { run.end(RunEnd(game.moves, finished = false)); run.begin(); game = PairsGame.deal(random); session = reduceSession(session, SessionEvent.Restart) },
|
||||
onExit = { session = reduceSession(session, SessionEvent.Exit) })
|
||||
if (stage == ClassicStage.Result) {
|
||||
val newBest = bestBefore == 0 || game.moves < bestBefore
|
||||
ClassicResult(gameDef, "PAIRS · ALL ${game.cards.size / 2} PAIRED", "MOVES", "${game.moves}", newBest = newBest,
|
||||
previous = if (bestBefore > 0) "Previous best $bestBefore moves" else "Your first Pairs score", detail = null, heading = "ALL PAIRED",
|
||||
cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave)
|
||||
}
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Pairs · ${game.moves} moves · ${game.matched.size / 2} of ${game.cards.size / 2} pairs",
|
||||
onResume = { paused = false }, onRestart = { run.end(RunEnd(game.moves, finished = false)); deal() }, onExit = ::leave)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.SessionEvent
|
||||
import tv.orbit.classic.arcade.SessionState
|
||||
import tv.orbit.classic.arcade.reduceSession
|
||||
import tv.orbit.classic.arcade.rememberRun
|
||||
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
|
||||
@@ -21,20 +14,39 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
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.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.tv.material3.Text
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.SpeechBubble
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.rememberRun
|
||||
|
||||
/**
|
||||
* Patience for Orbit Arcade (Paul's approved list): the classic one-card-draw game, played with the remote. The pointer moves
|
||||
* over the stock, the turned card, the four home piles and the seven columns. OK on the stock turns a card; OK on a card picks
|
||||
* it up (in a column, up and down choose how deep), and OK again puts it down where the pointer is, if it may go there. Back
|
||||
* puts a held card back, or leaves. Every won game is counted on the box.
|
||||
* it up (from a column, its whole face-up run), and OK where it's to go puts down as many as fit there. OK twice sends a card
|
||||
* home. Back puts a held card back, and only pauses when nothing is held. Every won game is counted.
|
||||
*
|
||||
* Controls reworked 9 November 2026 (Paul: "Patience just seems broken"); the rules are as they always were. Before, Up in a
|
||||
* column chose how many cards to take, so reaching the top row took one press per face-up card; sending home needed a Menu key
|
||||
* the remote hasn't got; a move that wasn't allowed did nothing at all; and Back was spent by the TV moving focus.
|
||||
*/
|
||||
internal data class PlayingCard(val rank: Int, val suit: Int, val up: Boolean = true) {
|
||||
val red get() = suit == 1 || suit == 2
|
||||
@@ -47,30 +59,25 @@ internal const val WASTE = 1
|
||||
internal val HOMES = 2..5
|
||||
internal val COLUMNS = 6..12
|
||||
|
||||
/** Where the pointer is ([pile], and in a column how many face-up cards from the bottom it takes), and what's held. */
|
||||
internal data class PatienceGame(val piles: List<List<PlayingCard>>, val pile: Int = 6, val depth: Int = 1, val held: Pair<Int, Int>? = null, val moves: Int = 0) {
|
||||
/** Where the pointer is, what's held ([held]: the pile and how many cards), the moves made, and moves refused (for the "can't go there"). */
|
||||
internal data class PatienceGame(val piles: List<List<PlayingCard>>, val pile: Int = 6, val held: Pair<Int, Int>? = null, val moves: Int = 0, val refusals: Int = 0) {
|
||||
val won get() = HOMES.all { piles[it].size == 13 }
|
||||
|
||||
private fun faceUp(i: Int) = piles[i].takeLastWhile { it.up }.size
|
||||
fun faceUp(i: Int) = piles[i].takeLastWhile { it.up }.size
|
||||
|
||||
fun point(to: Int) = copy(pile = to, depth = 1)
|
||||
fun point(to: Int) = copy(pile = to)
|
||||
|
||||
/** Left and right along the row; up and down between the rows, or deeper and shallower within a column. */
|
||||
/** Left and right along the row; up and down between the two rows, in one press. */
|
||||
fun steer(dx: Int, dy: Int): PatienceGame {
|
||||
if (dx != 0) {
|
||||
val row = if (pile in COLUMNS) COLUMNS.toList() else listOf(STOCK, WASTE) + HOMES.toList()
|
||||
return point(row[(row.indexOf(pile) + dx).coerceIn(0, row.size - 1)])
|
||||
}
|
||||
if (pile in COLUMNS) {
|
||||
if (dy < 0 && held == null && depth < faceUp(pile)) return copy(depth = depth + 1)
|
||||
if (dy > 0 && depth > 1) return copy(depth = depth - 1)
|
||||
if (dy < 0) return point(listOf(STOCK, WASTE, WASTE, 2, 3, 4, 5)[pile - 6])
|
||||
return this
|
||||
}
|
||||
if (pile in COLUMNS) return if (dy < 0) point(listOf(STOCK, WASTE, WASTE, 2, 3, 4, 5)[pile - 6]) else this
|
||||
return if (dy > 0) point(when (pile) { STOCK -> 6; WASTE -> 7; else -> pile + 7 }) else this
|
||||
}
|
||||
|
||||
/** Whether [card] may go on pile [to]: a home pile builds up by suit from the ace, a column down in alternate colours from a king. */
|
||||
/** Whether [cards] may go on pile [to]: a home pile builds up by suit from the ace, a column down in alternate colours from a king. */
|
||||
fun allowed(cards: List<PlayingCard>, to: Int): Boolean {
|
||||
val card = cards.first(); val top = piles[to].lastOrNull()
|
||||
return when (to) {
|
||||
@@ -80,16 +87,26 @@ internal data class PatienceGame(val piles: List<List<PlayingCard>>, val pile: I
|
||||
}
|
||||
}
|
||||
|
||||
/** OK: turn a stock card, pick up, or put down. */
|
||||
/** How many of the [n] held from [from] go on [to]: in a face-up run only one count can ever fit, so it's found, not chosen. 0 when none. */
|
||||
fun fitting(from: Int, n: Int, to: Int): Int = (n downTo 1).firstOrNull { allowed(piles[from].takeLast(it), to) } ?: 0
|
||||
|
||||
/** The home pile the top card of [from] can go to, if any. */
|
||||
fun homeFor(from: Int): Int? = piles[from].lastOrNull()?.takeIf { it.up }?.let { c -> HOMES.firstOrNull { allowed(listOf(c), it) } }
|
||||
|
||||
private fun moveCards(from: Int, n: Int, to: Int): PatienceGame {
|
||||
val cards = piles[from].takeLast(n)
|
||||
val next = piles.toMutableList()
|
||||
next[from] = piles[from].dropLast(n).let { left -> if (left.isNotEmpty() && !left.last().up) left.dropLast(1) + left.last().copy(up = true) else left }
|
||||
next[to] = piles[to] + cards
|
||||
return copy(piles = next, held = null, moves = moves + 1)
|
||||
}
|
||||
|
||||
/** OK: turn a stock card, pick up, or put down. OK again on the pile it came from sends the card home if it can go, or puts it back. */
|
||||
fun press(): PatienceGame {
|
||||
held?.let { (from, n) ->
|
||||
if (pile == from) return copy(held = null)
|
||||
val cards = piles[from].takeLast(n)
|
||||
if (!allowed(cards, pile)) return this
|
||||
val next = piles.toMutableList()
|
||||
next[from] = piles[from].dropLast(n).let { left -> if (left.isNotEmpty() && !left.last().up) left.dropLast(1) + left.last().copy(up = true) else left }
|
||||
next[pile] = piles[pile] + cards
|
||||
return copy(piles = next, held = null, depth = 1, moves = moves + 1)
|
||||
if (pile == from) return homeFor(from)?.let { moveCards(from, 1, it) } ?: copy(held = null)
|
||||
val k = fitting(from, n, pile)
|
||||
return if (k == 0) copy(refusals = refusals + 1) else moveCards(from, k, pile)
|
||||
}
|
||||
return when (pile) {
|
||||
STOCK -> {
|
||||
@@ -99,17 +116,17 @@ internal data class PatienceGame(val piles: List<List<PlayingCard>>, val pile: I
|
||||
copy(piles = next)
|
||||
}
|
||||
WASTE, in HOMES -> if (piles[pile].isEmpty()) this else copy(held = pile to 1)
|
||||
else -> if (faceUp(pile) == 0) this else copy(held = pile to depth.coerceAtMost(faceUp(pile)))
|
||||
else -> if (faceUp(pile) == 0) this else copy(held = pile to faceUp(pile))
|
||||
}
|
||||
}
|
||||
|
||||
/** Sends the card under the pointer to its home pile if it can go, the usual shortcut. */
|
||||
/** Sends the card under the pointer to its home pile if it can go (the Menu key, for remotes that have one). */
|
||||
fun sendHome(): PatienceGame {
|
||||
if (held != null || pile !in listOf(WASTE) + COLUMNS.toList() || piles[pile].isEmpty() || !piles[pile].last().up) return this
|
||||
val home = HOMES.firstOrNull { allowed(listOf(piles[pile].last()), it) } ?: return this
|
||||
return copy(held = pile to 1, pile = home).press().copy(pile = pile)
|
||||
if (held != null || pile !in listOf(WASTE) + COLUMNS.toList()) return this
|
||||
return homeFor(pile)?.let { moveCards(pile, 1, it) } ?: copy(refusals = refusals + 1)
|
||||
}
|
||||
|
||||
/** Back with a card in hand: it goes back where it was. */
|
||||
fun drop() = copy(held = null)
|
||||
|
||||
companion object {
|
||||
@@ -124,121 +141,134 @@ internal data class PatienceGame(val piles: List<List<PlayingCard>>, val pile: I
|
||||
}
|
||||
}
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
private val CardW = 64.dp
|
||||
private val CardH = 88.dp
|
||||
private val CardW = 76.dp
|
||||
private val CardH = 104.dp
|
||||
/** Held cards: lifted and ringed in cyan. The pointer: the yellow ring, as everywhere in the Arcade. Never the same. */
|
||||
private val HeldRing = ArcadeColours.Cyan
|
||||
private val PointRing = ArcadeColours.Yellow
|
||||
|
||||
@Composable
|
||||
private fun CardFace(card: PlayingCard?, empty: String = "", modifier: Modifier = Modifier) {
|
||||
Box(modifier.width(CardW).height(CardH).background(when { card == null -> Color(0x22FFFFFF); card.up -> Color(0xFFF4F6FB); else -> NightPanel }, RoundedCornerShape(6.dp))
|
||||
.border(1.dp, if (card?.up == false) NightBlue else Color(0x55FFFFFF), RoundedCornerShape(6.dp)).padding(5.dp)) {
|
||||
Box(modifier.width(CardW).height(CardH).background(when { card == null -> Color(0x22FFFFFF); card.up -> Color(0xFFF4F6FB); else -> ArcadeColours.Panel }, RoundedCornerShape(7.dp))
|
||||
.border(1.dp, if (card?.up == false) ArcadeColours.Line else Color(0x55FFFFFF), RoundedCornerShape(7.dp)).padding(5.dp)) {
|
||||
when {
|
||||
card == null -> Text(empty, Modifier.align(Alignment.Center), color = NightMuted.copy(alpha = .6f), fontSize = 14.sp)
|
||||
card == null -> Text(empty, Modifier.align(Alignment.Center), color = ArcadeColours.Muted.copy(alpha = .6f), fontSize = 18.sp)
|
||||
card.up -> {
|
||||
val colour = if (card.red) Color(0xFFD32F2F) else Color(0xFF0B1B44)
|
||||
Text(card.label, color = colour, fontSize = 15.sp, fontWeight = FontWeight.Bold)
|
||||
Text("♠♥♦♣"[card.suit].toString(), Modifier.align(Alignment.Center), color = colour, fontSize = 26.sp)
|
||||
Text(card.label, color = colour, fontSize = 18.sp, fontWeight = FontWeight.Bold)
|
||||
Text("♠♥♦♣"[card.suit].toString(), Modifier.align(Alignment.Center), color = colour, fontSize = 32.sp)
|
||||
}
|
||||
// Ollie on every card back (Paul, 6 November 2026: each game hosted by one of the cast).
|
||||
else -> androidx.compose.foundation.Canvas(Modifier.fillMaxSize()) { drawOrbMascot(center, size.minDimension * .24f) }
|
||||
else -> Canvas(Modifier.fillMaxSize()) { drawOrbMascot(center, size.minDimension * .24f) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A ring round a card: the held one lifted a little. */
|
||||
private fun Modifier.ring(pointed: Boolean, held: Boolean): Modifier = when {
|
||||
held -> offset(y = (-6).dp).border(3.dp, HeldRing, RoundedCornerShape(7.dp))
|
||||
pointed -> border(3.dp, PointRing, RoundedCornerShape(7.dp))
|
||||
else -> this
|
||||
}
|
||||
|
||||
/** How far apart a column's cards sit, so even the longest column fits: face-down cards close, face-up ones as far as there's room. */
|
||||
internal fun patienceSteps(down: Int, up: Int, room: Float, cardH: Float, downStep: Float = 8f, upMax: Float = 26f): Float =
|
||||
if (up <= 1) upMax else ((room - cardH - down * downStep) / (up - 1)).coerceIn(12f, upMax)
|
||||
|
||||
@Composable
|
||||
internal fun PatienceScreen(play: ArcadePlay) {
|
||||
val wins = play.best
|
||||
val gameDef = ArcadeGames.Patience
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val random = remember { java.util.Random() }
|
||||
var game by remember { mutableStateOf(PatienceGame.deal(random)) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var winsBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
// The shared pause (Arcade Stage C): Back puts a held card back, otherwise pauses instead of leaving at once.
|
||||
var session by remember { mutableStateOf<SessionState>(SessionState.Play) }
|
||||
LaunchedEffect(session) { if (session == SessionState.Exited) play.onLeave() else if (session == SessionState.Play && !game.won) runCatching { focus.requestFocus() } }
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
// A won game counts for this profile; leaving part-way counts nothing.
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.moves, finished = game.won) }
|
||||
LaunchedEffect(game.won) {
|
||||
if (game.won) {
|
||||
run.end(RunEnd(game.moves, finished = true))
|
||||
session = reduceSession(session, SessionEvent.Finish(RunEnd(game.moves, true), newBest = false))
|
||||
menuFocus.requestFocus()
|
||||
} else { run.begin(); focus.requestFocus() }
|
||||
fun deal() { winsBefore = latestPlay.best; game = PatienceGame.deal(random); run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.moves, finished = game.won)); latestPlay.onLeave() }
|
||||
LaunchedEffect(game.won) { if (game.won && stage == ClassicStage.Play) { run.end(RunEnd(game.moves, finished = true)); stage = ClassicStage.Result } }
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
// "That can't go there", for a moment after a refused move.
|
||||
var refusedShown by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(game.refusals) { if (game.refusals > 0) { refusedShown = true; kotlinx.coroutines.delay(1_400); refusedShown = false } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { if (game.held != null) game = game.drop() else paused = true }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, ArcadeColours.Green, "Deal you in?", listOf("Games won" to "${play.best}"), timed = false, difficulty = play.difficulty,
|
||||
refocus = !howTo, onPlay = ::deal, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, playLabel = "Deal",
|
||||
note = "Pick a card up and OK where it goes: as many as fit there move together. OK twice sends a card home.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
BackHandler(session == SessionState.Play || session is SessionState.Result) {
|
||||
if (session == SessionState.Play && game.held != null) game = game.drop() else session = reduceSession(session, SessionEvent.Back)
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused,
|
||||
// Back by context: a held card goes back first; with nothing held, Back pauses.
|
||||
active = { game.held != null }, cancel = { game = game.drop() }, pause = { paused = true }) { key, native ->
|
||||
if (native.action != KeyEvent.ACTION_DOWN || game.won) return@gameKeys key != ArcadeKey.Other
|
||||
val next = when (key) {
|
||||
ArcadeKey.Left -> game.steer(-1, 0)
|
||||
ArcadeKey.Right -> game.steer(1, 0)
|
||||
ArcadeKey.Up -> game.steer(0, -1)
|
||||
ArcadeKey.Down -> game.steer(0, 1)
|
||||
ArcadeKey.Ok -> if (native.repeatCount > 0) null else game.press()
|
||||
ArcadeKey.Menu -> game.sendHome()
|
||||
else -> if (native.keyCode == KeyEvent.KEYCODE_PROG_RED) game.sendHome() else null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
Row(Modifier.fillMaxSize().background(Color(0xFF0A2A1F)).padding(16.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (native.action != KeyEvent.ACTION_DOWN || game.won || session != SessionState.Play) return@onPreviewKeyEvent false
|
||||
val next = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> game.steer(-1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> game.steer(1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_UP -> game.steer(0, -1)
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> game.steer(0, 1)
|
||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> if (native.repeatCount > 0) null else game.press()
|
||||
KeyEvent.KEYCODE_MENU, KeyEvent.KEYCODE_PROG_RED -> game.sendHome()
|
||||
else -> null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}, horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
Column(Modifier.width(170.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("PATIENCE", color = Honey, fontFamily = Marquee, fontSize = 34.sp)
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Text("MOVES", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(game.moves.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text("GAMES WON", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(wins.toString(), color = Color.White, fontFamily = Marquee, fontSize = 32.sp)
|
||||
ClassicPlayFrame(backdrop, keys,
|
||||
footer = if (game.held != null) listOf(Control("◀▶▲▼", "Where it goes"), Control("OK", "Put it down"), Control("OK twice", "Send home"), Control("Back", "Put back"))
|
||||
else listOf(Control("◀▶▲▼", "Point"), Control("OK", "Pick up"), Control("OK twice", "Send home"), Control("Back", "Pause")),
|
||||
hud = {
|
||||
HudLabel("MOVES"); HudValue("${game.moves}")
|
||||
Spacer(Modifier.height(8.dp))
|
||||
HudLabel("GAMES WON"); HudValue("${maxOf(play.best, winsBefore)}")
|
||||
Spacer(Modifier.height(8.dp))
|
||||
HudLabel("IN HAND")
|
||||
Text(game.held?.let { (from, n) -> game.piles[from].takeLast(n).first().label + if (n > 1) " and ${n - 1} more" else "" } ?: "Nothing",
|
||||
color = if (game.held != null) HeldRing else ArcadeColours.Muted, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄►▲▼ Point", color = NightMuted, fontSize = 13.sp)
|
||||
Text("OK Pick up / put down", color = NightMuted, fontSize = 13.sp)
|
||||
Text("▲▼ in a column: how many", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Back Put back / pause", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Menu Send a card home", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight()) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
if (refusedShown) SpeechBubble("That can't go there") else if (game.held != null && game.homeFor(game.held!!.first) != null && game.pile == game.held!!.first) SpeechBubble("OK again: home!")
|
||||
Canvas(Modifier.size(56.dp)) { drawOrbMascot(center, size.minDimension * .34f) }
|
||||
}) {
|
||||
BoxWithConstraints(Modifier.fillMaxSize()) {
|
||||
val room = maxHeight.value - CardH.value - 12f
|
||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
listOf(STOCK, WASTE, -1, 2, 3, 4, 5).forEach { i ->
|
||||
if (i < 0) Spacer(Modifier.width(CardW)) else {
|
||||
val pointed = game.pile == i; val holding = game.held?.first == i
|
||||
CardFace(game.piles[i].lastOrNull()?.let { if (i == STOCK) it.copy(up = false) else it }, if (i == STOCK) "↺" else if (i in HOMES) "A" else "",
|
||||
Modifier.border(if (pointed) 3.dp else 0.dp, if (holding) Honey else NightYellow, RoundedCornerShape(6.dp)))
|
||||
Modifier.ring(pointed = game.pile == i, held = game.held?.first == i))
|
||||
}
|
||||
}
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
for (c in COLUMNS) {
|
||||
val cards = game.piles[c]
|
||||
val pointed = game.pile == c
|
||||
val chosen = if (game.held?.first == c) game.held!!.second else if (pointed) game.depth else 0
|
||||
Box(Modifier.width(CardW).height(CardH + 22.dp * 12)) {
|
||||
if (cards.isEmpty()) CardFace(null, "K", Modifier.border(if (pointed) 3.dp else 0.dp, NightYellow, RoundedCornerShape(6.dp)))
|
||||
val held = game.held?.takeIf { it.first == c }?.second ?: 0
|
||||
val down = cards.size - game.faceUp(c)
|
||||
val upStep = patienceSteps(down, game.faceUp(c), room, CardH.value).dp
|
||||
Box(Modifier.width(CardW).height(room.dp)) {
|
||||
if (cards.isEmpty()) CardFace(null, "K", Modifier.ring(pointed = game.pile == c, held = false))
|
||||
cards.forEachIndexed { n, card ->
|
||||
val inRun = n >= cards.size - chosen
|
||||
CardFace(card, modifier = Modifier.offset(y = (if (card.up) 22.dp else 12.dp) * n - offsetFix(cards, n))
|
||||
.border(if (inRun) 3.dp else 0.dp, if (game.held?.first == c) Honey else NightYellow, RoundedCornerShape(6.dp)))
|
||||
val y: Dp = if (n < down) 8.dp * n else 8.dp * down + upStep * (n - down)
|
||||
CardFace(card, modifier = Modifier.offset(y = y).ring(pointed = game.pile == c && n == cards.lastIndex && held == 0, held = n >= cards.size - held))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (game.won) Column(Modifier.align(Alignment.Center).background(NightNavy, RoundedCornerShape(6.dp)).border(2.dp, Honey, RoundedCornerShape(6.dp)).padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text("WON!", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
Text("In ${game.moves} moves", color = Color.White, fontSize = 16.sp)
|
||||
OrbitButton("Deal again", Modifier.width(200.dp).focusRequester(menuFocus), onClick = { game = PatienceGame.deal(random); session = reduceSession(session, SessionEvent.PlayAgain) })
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (session is SessionState.Pause) ArcadePauseMenu(ArcadeGames.Patience, "Patience · ${game.moves} moves",
|
||||
onResume = { session = reduceSession(session, SessionEvent.Resume) },
|
||||
onRestart = { run.end(RunEnd(game.moves, finished = false)); run.begin(); game = PatienceGame.deal(random); session = reduceSession(session, SessionEvent.Restart) },
|
||||
onExit = { session = reduceSession(session, SessionEvent.Exit) })
|
||||
if (stage == ClassicStage.Result) ClassicResult(gameDef, "PATIENCE · WON IN ${game.moves} MOVES", "GAMES WON", "${winsBefore + 1}", newBest = false,
|
||||
previous = "Every suit home, ace to king", detail = null, heading = "WON!", againLabel = "Deal again", cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave)
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Patience · ${game.moves} moves",
|
||||
onResume = { paused = false }, onRestart = { run.end(RunEnd(game.moves, finished = false)); deal() }, onExit = ::leave)
|
||||
}
|
||||
}
|
||||
|
||||
/** Face-down cards sit closer together than face-up ones: the offset saved above card [n]. */
|
||||
private fun offsetFix(cards: List<PlayingCard>, n: Int): Dp = if (!cards[n].up) 0.dp else 10.dp * cards.take(n).count { !it.up }
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.rememberRun
|
||||
@@ -133,8 +149,6 @@ internal class SkyGame(val puzzle: SkyPuzzle, val placed: Set<Int> = emptySet(),
|
||||
/** The puzzle of the day: the same all day for everyone with Orbit. */
|
||||
internal fun skyDaily(day: java.time.LocalDate) = skyMake(java.util.Random(day.toEpochDay() * 7_919 + 61))
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
|
||||
/** The cast in region order, each region in its member's colour. */
|
||||
internal val SkyCast = listOf("Ollie", "Blaze", "Zip", "Drift", "Luna", "Bumble")
|
||||
@@ -158,7 +172,7 @@ internal fun DrawScope.drawSkyBoard(game: SkyGame, showCursor: Boolean = true) {
|
||||
val regions = game.puzzle.regions
|
||||
for (i in regions.indices) {
|
||||
val at = origin + Offset(i % SKY_SIZE * cell, i / SKY_SIZE * cell)
|
||||
drawRect(NightNavy, at, Size(cell, cell))
|
||||
drawRect(ArcadeColours.Night, at, Size(cell, cell))
|
||||
drawRect(SkyColours[regions[i]].copy(alpha = .42f), at, Size(cell, cell))
|
||||
if (i in game.placed) drawSkyFace(regions[i], at + Offset(cell / 2, cell / 2), cell * .36f)
|
||||
else if (i in game.crossed) {
|
||||
@@ -178,87 +192,112 @@ internal fun DrawScope.drawSkyBoard(game: SkyGame, showCursor: Boolean = true) {
|
||||
drawRoundRect(Color.White, origin, Size(cell * SKY_SIZE, cell * SKY_SIZE), CornerRadius(cell * .08f), style = Stroke(cell * .07f))
|
||||
if (showCursor && !game.done && !game.out) {
|
||||
val at = origin + Offset(game.cursor % SKY_SIZE * cell, game.cursor / SKY_SIZE * cell)
|
||||
drawRoundRect(NightYellow, at + Offset(cell * .05f, cell * .05f), Size(cell * .9f, cell * .9f), CornerRadius(cell * .12f), style = Stroke(cell * .08f))
|
||||
drawRoundRect(ArcadeColours.Yellow, at + Offset(cell * .05f, cell * .05f), Size(cell * .9f, cell * .9f), CornerRadius(cell * .12f), style = Stroke(cell * .08f))
|
||||
}
|
||||
}
|
||||
|
||||
/** A heart, drawn to the space it's given (it used to be drawn in raw pixels, so it didn't scale with the screen). */
|
||||
private fun androidx.compose.ui.graphics.drawscope.DrawScope.drawHeart(c: Offset, r: Float, full: Boolean) {
|
||||
val heart = androidx.compose.ui.graphics.Path().apply {
|
||||
moveTo(c.x, c.y + r * .9f); cubicTo(c.x - r * 1.6f, c.y - r * .2f, c.x - r * .7f, c.y - r * 1.3f, c.x, c.y - r * .5f)
|
||||
cubicTo(c.x + r * .7f, c.y - r * 1.3f, c.x + r * 1.6f, c.y - r * .2f, c.x, c.y + r * .9f); close()
|
||||
}
|
||||
if (full) drawPath(heart, ArcadeColours.Pink) else drawPath(heart, ArcadeColours.Muted.copy(alpha = .5f), style = Stroke(r * .18f))
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun SkydokuScreen(play: ArcadePlay) {
|
||||
val solved = play.best
|
||||
val gameDef = ArcadeGames.Sky
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val random = remember { java.util.Random() }
|
||||
val today = remember { java.time.LocalDate.now() }
|
||||
val dailyDone = remember { play.level["daily"] == today.toString() }
|
||||
var dailyDone by remember { mutableStateOf(play.level["daily"] == today.toString()) }
|
||||
var daily by remember { mutableStateOf(!dailyDone) }
|
||||
var game by remember { mutableStateOf(SkyGame(if (!dailyDone) skyDaily(today) else skyMake(random))) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
// A solved puzzle counts for this profile; today's puzzle is then done for today (Arcade Stage C: per profile).
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.hearts, finished = false) }
|
||||
LaunchedEffect(game.done) {
|
||||
if (!game.done) { run.begin(); return@LaunchedEffect }
|
||||
if (daily) play.setLevel("daily", today.toString())
|
||||
run.end(RunEnd(game.hearts, finished = true, detail = if (daily) "Today's puzzle" else null))
|
||||
// Puzzles are made off the main thread (making one and checking it has only one answer could stutter the screen):
|
||||
// the first is made while the title shows.
|
||||
var game by remember { mutableStateOf<SkyGame?>(null) }
|
||||
val scope = rememberCoroutineScope()
|
||||
fun make(todays: Boolean, then: () -> Unit = {}) {
|
||||
daily = todays; game = null
|
||||
scope.launch { val puzzle = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Default) { if (todays) skyDaily(today) else skyMake(random) }; game = SkyGame(puzzle); then() }
|
||||
}
|
||||
LaunchedEffect(paused, game.done, game.out) { if (paused || game.done || game.out) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
BackHandler { if (!game.done && !game.out) paused = !paused else play.onLeave() }
|
||||
Row(Modifier.fillMaxSize().arcadeBackdrop().padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (native.action != KeyEvent.ACTION_DOWN || paused || game.done || game.out) return@onPreviewKeyEvent false
|
||||
game = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> game.move(-1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> game.move(1, 0)
|
||||
KeyEvent.KEYCODE_DPAD_UP -> game.move(0, -1)
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> game.move(0, 1)
|
||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> game.place()
|
||||
else -> return@onPreviewKeyEvent false
|
||||
LaunchedEffect(Unit) { make(!dailyDone) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var startWhenReady by remember { mutableStateOf(false) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
val focus = remember { FocusRequester() }
|
||||
val backdrop = ArcadeLook.forGame(gameDef.id)
|
||||
// A solved puzzle counts for this profile; today's puzzle is then done for today (per profile). Out of hearts counts nothing.
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game?.hearts ?: 0, finished = false) }
|
||||
fun begin() { run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
LaunchedEffect(game, startWhenReady) { if (startWhenReady && game != null) { startWhenReady = false; begin() } }
|
||||
fun startNew() { make(false) { begin() } }
|
||||
val g = game
|
||||
LaunchedEffect(g?.done, g?.out) {
|
||||
if (g == null || stage != ClassicStage.Play) return@LaunchedEffect
|
||||
if (g.done) {
|
||||
if (daily) { latestPlay.setLevel("daily", today.toString()); dailyDone = true }
|
||||
run.end(RunEnd(g.hearts, finished = true, detail = if (daily) "Today's puzzle" else null))
|
||||
stage = ClassicStage.Result
|
||||
} else if (g.out) stage = ClassicStage.Result
|
||||
}
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, backdrop, OrbCharacter.Luna.colour, if (dailyDone) "Today's is done: fancy another?" else "Today's puzzle is ready!",
|
||||
listOf("Solved" to "${play.best}", "Today's puzzle" to if (dailyDone) "Done ★" else "Not yet"),
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, playLabel = if (dailyDone) "New puzzle" else "Today's puzzle",
|
||||
onPlay = { if (game != null) begin() else startWhenReady = true }, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "One in every row and column, and no two touching, not even at the corners. Every puzzle can be solved by logic alone.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused && g != null, pause = { paused = true }) { key, native ->
|
||||
val cur = game ?: return@gameKeys false
|
||||
if (native.action != KeyEvent.ACTION_DOWN || cur.done || cur.out) return@gameKeys key != ArcadeKey.Other
|
||||
val next = when (key) {
|
||||
ArcadeKey.Left -> cur.move(-1, 0)
|
||||
ArcadeKey.Right -> cur.move(1, 0)
|
||||
ArcadeKey.Up -> cur.move(0, -1)
|
||||
ArcadeKey.Down -> cur.move(0, 1)
|
||||
ArcadeKey.Ok -> if (native.repeatCount > 0) cur else cur.place()
|
||||
else -> null
|
||||
}
|
||||
true
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(200.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("SKYDOKU", color = Honey, fontFamily = Marquee, fontSize = 32.sp)
|
||||
Text(if (daily) "TODAY'S PUZZLE" else "NEW PUZZLE", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Canvas(Modifier.height(26.dp).fillMaxWidth()) {
|
||||
repeat(SKY_HEARTS) { k ->
|
||||
val c = Offset(13f + k * 34f, size.height / 2)
|
||||
val full = k < game.hearts
|
||||
val heart = androidx.compose.ui.graphics.Path().apply {
|
||||
moveTo(c.x, c.y + 9f); cubicTo(c.x - 16f, c.y - 2f, c.x - 7f, c.y - 13f, c.x, c.y - 5f); cubicTo(c.x + 7f, c.y - 13f, c.x + 16f, c.y - 2f, c.x, c.y + 9f); close()
|
||||
}
|
||||
if (full) drawPath(heart, Color(0xFFFF6B8A)) else drawPath(heart, NightMuted.copy(alpha = .5f), style = Stroke(2f))
|
||||
}
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶▲▼", "Move"), Control("OK", "Place"), Control("Back", "Pause")), hud = {
|
||||
HudLabel(if (daily) "TODAY'S PUZZLE" else "NEW PUZZLE")
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text("Put each of the cast in their own colour.", color = Color.White, fontSize = 14.sp)
|
||||
Text("One in every row and column, and no two touching, not even at the corners.", color = NightMuted, fontSize = 13.sp)
|
||||
Text("SOLVED", color = NightMuted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp, modifier = Modifier.padding(top = 6.dp))
|
||||
Text(solved.toString(), color = Color.White, fontFamily = Marquee, fontSize = 28.sp)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄►▲▼ Move OK Place", color = NightMuted, fontSize = 13.sp)
|
||||
Text("Back Pause", color = NightMuted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
Canvas(Modifier.fillMaxHeight().aspectRatio(1f)) { drawSkyBoard(game) }
|
||||
// Who goes in the region under the cursor.
|
||||
Column(Modifier.width(110.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
val region = game.puzzle.regions[game.cursor]
|
||||
Canvas(Modifier.size(72.dp)) { drawCircle(SkyColours[region].copy(alpha = .35f), size.minDimension / 2); drawSkyFace(region, center, size.minDimension * .4f) }
|
||||
Text(SkyCast[region], color = Color.White, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
||||
Text("goes here?", color = NightMuted, fontSize = 12.sp)
|
||||
}
|
||||
}
|
||||
if (paused || game.done || game.out) Column(Modifier.background(NightNavy, RoundedCornerShape(6.dp)).border(2.dp, Honey, RoundedCornerShape(6.dp)).padding(20.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(if (game.done) "SOLVED!" else if (game.out) "OUT OF HEARTS" else "PAUSED", color = Honey, fontFamily = Marquee, fontSize = 30.sp)
|
||||
if (game.done) CastCheer()
|
||||
if (game.out) Text("Every puzzle can be solved by logic alone.", color = Color.White, fontSize = 14.sp)
|
||||
if (!game.done && !game.out) OrbitButton("Carry on", Modifier.width(220.dp).focusRequester(menuFocus), onClick = { paused = false })
|
||||
if (game.out) OrbitButton("Try it again", Modifier.width(220.dp).focusRequester(menuFocus), onClick = { game = game.again() })
|
||||
OrbitButton("New puzzle", Modifier.width(220.dp).then(if (game.done) Modifier.focusRequester(menuFocus) else Modifier), onClick = {
|
||||
daily = false; game = SkyGame(skyMake(random)); paused = false
|
||||
})
|
||||
OrbitButton("Leave the game", Modifier.width(220.dp), onClick = play.onLeave)
|
||||
HudLabel("HEARTS")
|
||||
Canvas(Modifier.height(30.dp).fillMaxWidth()) { val r = size.height * .4f; repeat(SKY_HEARTS) { k -> drawHeart(Offset(r * 1.4f + k * r * 3.2f, size.height / 2), r, k < (g?.hearts ?: SKY_HEARTS)) } }
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("SOLVED"); HudValue("${play.best}")
|
||||
}, side = {
|
||||
// Who goes in the region under the cursor.
|
||||
if (g != null) {
|
||||
val region = g.puzzle.regions[g.cursor]
|
||||
HudLabel("THIS COLOUR")
|
||||
Canvas(Modifier.size(72.dp)) { drawCircle(SkyColours[region].copy(alpha = .35f), size.minDimension / 2); drawSkyFace(region, center, size.minDimension * .4f) }
|
||||
Text(SkyCast[region], color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
||||
Text("goes here?", color = ArcadeColours.Muted, fontSize = 14.sp)
|
||||
}
|
||||
}) {
|
||||
if (g != null) Canvas(Modifier.fillMaxHeight().aspectRatio(1f)) { drawSkyBoard(g) }
|
||||
else Text("Making a puzzle…", color = ArcadeColours.Muted, fontSize = 16.sp)
|
||||
}
|
||||
if (stage == ClassicStage.Result && g != null) {
|
||||
if (g.done) ClassicResult(gameDef, if (daily) "SKYDOKU · TODAY'S PUZZLE" else "SKYDOKU · NEW PUZZLE", "SOLVED", "${maxOf(play.best, 1)}", newBest = false,
|
||||
previous = "With ${g.hearts} of $SKY_HEARTS hearts left", detail = if (daily) "Today's puzzle is done. A new one tomorrow." else null, heading = "SOLVED!",
|
||||
againLabel = "New puzzle", cheer = Mascot.Bumble, onAgain = ::startNew, onBack = { latestPlay.onLeave() })
|
||||
else ClassicResult(gameDef, "SKYDOKU · OUT OF HEARTS", "PLACED", "${g.placed.size} of $SKY_SIZE", newBest = false,
|
||||
previous = "Every puzzle can be solved by logic alone.", detail = null, heading = "OUT OF HEARTS", againLabel = "Try it again",
|
||||
extra = "New puzzle" to ::startNew, cheer = Mascot.Drift, onAgain = { game = g.again(); paused = false; stage = ClassicStage.Play }, onBack = { latestPlay.onLeave() })
|
||||
}
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Skydoku · ${g?.placed?.size ?: 0} of $SKY_SIZE placed",
|
||||
onResume = { paused = false }, onRestart = { game = g?.again(); paused = false }, onExit = { latestPlay.onLeave() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ClassicPlayFrame
|
||||
import tv.orbit.classic.arcade.ClassicResult
|
||||
import tv.orbit.classic.arcade.ClassicStage
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.Mascot
|
||||
import tv.orbit.classic.arcade.classicPace
|
||||
import tv.orbit.classic.arcade.classicPanel
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.previousLine
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.animation.Crossfade
|
||||
@@ -53,10 +71,18 @@ internal enum class SnakeDirection(val dx: Int, val dy: Int) {
|
||||
|
||||
internal data class SnakeCell(val x: Int, val y: Int)
|
||||
|
||||
/** The whole game, with no screen in it. Hit a wall or yourself and it's over. */
|
||||
internal data class SnakeGame(val width: Int, val height: Int, val body: List<SnakeCell>, val heading: SnakeDirection, val wanted: SnakeDirection, val food: SnakeCell, val score: Int = 0, val alive: Boolean = true) {
|
||||
/** A turn back on yourself is ignored, as it could only ever end the game. */
|
||||
fun turn(direction: SnakeDirection) = if (direction == heading.opposite) this else copy(wanted = direction)
|
||||
/**
|
||||
* The whole game, with no screen in it. Hit a wall or yourself and it's over. [queued] is a second turn pressed before the
|
||||
* first was taken (9 November 2026: two quick presses within one step used to keep only the last, so a tight double turn
|
||||
* was lost); it's taken on the next step.
|
||||
*/
|
||||
internal data class SnakeGame(val width: Int, val height: Int, val body: List<SnakeCell>, val heading: SnakeDirection, val wanted: SnakeDirection, val food: SnakeCell, val score: Int = 0, val alive: Boolean = true,
|
||||
val queued: SnakeDirection? = null) {
|
||||
/** A turn back on yourself is ignored, as it could only ever end the game. A turn while one is waiting goes next. */
|
||||
fun turn(direction: SnakeDirection): SnakeGame {
|
||||
if (wanted != heading) return if (direction == wanted || direction == wanted.opposite) this else copy(queued = direction)
|
||||
return if (direction == heading.opposite) this else copy(wanted = direction)
|
||||
}
|
||||
|
||||
fun step(random: java.util.Random): SnakeGame {
|
||||
if (!alive) return this
|
||||
@@ -65,10 +91,10 @@ internal data class SnakeGame(val width: Int, val height: Int, val body: List<Sn
|
||||
val eating = next == food
|
||||
// The tail moves away this step, so it's safe to follow it unless it's about to grow.
|
||||
val solid = if (eating) body else body.dropLast(1)
|
||||
if (next.x !in 0 until width || next.y !in 0 until height || next in solid) return copy(heading = wanted, alive = false)
|
||||
if (next.x !in 0 until width || next.y !in 0 until height || next in solid) return copy(heading = wanted, alive = false, queued = null)
|
||||
val grown = listOf(next) + solid
|
||||
return copy(body = grown, heading = wanted, food = if (eating) nextFood(width, height, grown, random) ?: food else food, score = if (eating) score + 10 else score,
|
||||
alive = grown.size < width * height)
|
||||
return copy(body = grown, heading = wanted, wanted = queued ?: wanted, queued = null, food = if (eating) nextFood(width, height, grown, random) ?: food else food,
|
||||
score = if (eating) score + 10 else score, alive = grown.size < width * height)
|
||||
}
|
||||
|
||||
/** Starts at a walking pace and quickens noticeably with every bite, up to a limit. */
|
||||
@@ -80,59 +106,27 @@ internal data class SnakeGame(val width: Int, val height: Int, val body: List<Sn
|
||||
val body = List(4) { SnakeCell(width / 4 - it, y) }
|
||||
return SnakeGame(width, height, body, SnakeDirection.Right, SnakeDirection.Right, nextFood(width, height, body, random)!!)
|
||||
}
|
||||
/** A free square at random: the same square the old list of every free square picked, without making that list. */
|
||||
fun nextFood(width: Int, height: Int, body: List<SnakeCell>, random: java.util.Random): SnakeCell? {
|
||||
val free = (0 until height).flatMap { y -> (0 until width).map { x -> SnakeCell(x, y) } } - body.toSet()
|
||||
return if (free.isEmpty()) null else free[random.nextInt(free.size)]
|
||||
val taken = body.toHashSet()
|
||||
val free = width * height - taken.size
|
||||
if (free <= 0) return null
|
||||
var k = random.nextInt(free)
|
||||
for (y in 0 until height) for (x in 0 until width) {
|
||||
val c = SnakeCell(x, y)
|
||||
if (c in taken) continue
|
||||
if (k-- == 0) return c
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val Marquee = FontFamily(Font(R.font.anton_regular))
|
||||
private val Honey = Color(0xFFFFD84A)
|
||||
|
||||
internal const val SNAKE_BACKDROPS = 4
|
||||
|
||||
/** A new backdrop every ten bites, going round. */
|
||||
internal fun snakeBackdrop(score: Int) = (score / 100) % SNAKE_BACKDROPS
|
||||
|
||||
/** Dim and still, so the snake and the food are always what stands out. */
|
||||
@Composable
|
||||
private fun SnakeBackdrop(scene: Int, modifier: Modifier) {
|
||||
Canvas(modifier) {
|
||||
val w = size.width
|
||||
val h = size.height
|
||||
val tops = listOf(Color(0xFF040A1E), Color(0xFF0A0620), Color(0xFF03101F), Color(0xFF0B0818))
|
||||
val bottoms = listOf(Color(0xFF071632), Color(0xFF160A30), Color(0xFF061C33), Color(0xFF1A0E1E))
|
||||
drawRect(Brush.verticalGradient(listOf(tops[scene], bottoms[scene])))
|
||||
val stars = java.util.Random(7L + scene)
|
||||
repeat(90) {
|
||||
drawCircle(Ink.copy(alpha = .12f + stars.nextFloat() * .28f), .8f + stars.nextFloat() * 1.4f, Offset(stars.nextFloat() * w, stars.nextFloat() * h))
|
||||
}
|
||||
when (scene) {
|
||||
// A nebula, soft and off to one side.
|
||||
1 -> {
|
||||
drawCircle(Brush.radialGradient(listOf(Color(0x33A050FF), Color.Transparent), Offset(w * .72f, h * .32f), h * .62f), h * .62f, Offset(w * .72f, h * .32f))
|
||||
drawCircle(Brush.radialGradient(listOf(Color(0x22FF5AA0), Color.Transparent), Offset(w * .3f, h * .7f), h * .5f), h * .5f, Offset(w * .3f, h * .7f))
|
||||
}
|
||||
// A ringed planet in the corner.
|
||||
2 -> {
|
||||
val planet = Offset(w * .84f, h * .8f)
|
||||
val radius = h * .26f
|
||||
drawCircle(Brush.radialGradient(listOf(Color(0x553A64C8), Color(0x331A2A66)), planet - Offset(radius * .4f, radius * .4f), radius * 1.4f), radius, planet)
|
||||
withTransform({ rotate(-14f, planet) }) {
|
||||
drawOval(Color(0x33FFD84A), Offset(planet.x - radius * 1.6f, planet.y - radius * .32f), Size(radius * 3.2f, radius * .64f), style = Stroke(2.5f))
|
||||
}
|
||||
}
|
||||
// The edge of a world, along the bottom.
|
||||
3 -> {
|
||||
val center = Offset(w * .5f, h * 2.1f)
|
||||
drawCircle(Brush.radialGradient(listOf(Color(0x44FF8A3D), Color.Transparent), center, h * 1.3f), h * 1.3f, center)
|
||||
drawCircle(Color(0xFF0B0818), h * 1.18f, center)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Where each piece of the snake is drawn, partway between two steps, so it glides from cell to cell rather than jumping. */
|
||||
internal fun snakeLine(game: SnakeGame, before: List<SnakeCell>?, progress: Float): List<Pair<Float, Float>> =
|
||||
game.body.mapIndexed { index, cell ->
|
||||
@@ -151,7 +145,7 @@ private fun SnakeField(game: SnakeGame, modifier: Modifier, before: List<SnakeCe
|
||||
val left = (size.width - cell * game.width) / 2
|
||||
val top = (size.height - cell * game.height) / 2
|
||||
for (y in 0 until game.height) for (x in 0 until game.width) if ((x + y) % 2 == 0)
|
||||
drawRect(Ink.copy(alpha = .025f), Offset(left + x * cell, top + y * cell), Size(cell, cell))
|
||||
drawRect(ArcadeColours.Ink.copy(alpha = .025f), Offset(left + x * cell, top + y * cell), Size(cell, cell))
|
||||
fun at(x: Float, y: Float) = Offset(left + (x + .5f) * cell, top + (y + .5f) * cell)
|
||||
drawPath(starPath(at(game.food.x.toFloat(), game.food.y.toFloat()), cell * .5f, cell * .22f, 0f), Color(0xFFFFDE59))
|
||||
val line = snakeLine(game, before, progress)
|
||||
@@ -169,79 +163,78 @@ private fun SnakeField(game: SnakeGame, modifier: Modifier, before: List<SnakeCe
|
||||
/** Runs until it's left. A reminder taking over the remote, or Orbit going out of sight, pauses it, so nobody loses a game to a pop-up. */
|
||||
@Composable
|
||||
internal fun SnakeScreen(play: ArcadePlay) {
|
||||
val best = play.best
|
||||
val gameDef = ArcadeGames.Snake
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
val random = remember { java.util.Random() }
|
||||
var game by remember { mutableStateOf(SnakeGame.start(30, 22, random)) }
|
||||
var before by remember { mutableStateOf<List<SnakeCell>?>(null) }
|
||||
var progress by remember { mutableFloatStateOf(1f) }
|
||||
var stage by remember { mutableStateOf(ClassicStage.Title) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var bestBefore by remember { mutableIntStateOf(play.best) }
|
||||
val focus = remember { FocusRequester() }
|
||||
PauseWhenHidden(game.alive) { paused = true }
|
||||
// Every run is saved when it ends, however it ends (Arcade Stage C): game over, Leave, or the screen going away.
|
||||
val pace = classicPace(play.difficulty)
|
||||
PauseWhenHidden(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false) }
|
||||
LaunchedEffect(game.alive) { if (game.alive) run.begin() else run.end(RunEnd(game.score, finished = true)) }
|
||||
// Steps on the clock, drawn on every frame between them.
|
||||
fun startRun() { bestBefore = latestPlay.best; game = SnakeGame.start(30, 22, random); before = null; progress = 1f; run.begin(); paused = false; stage = ClassicStage.Play }
|
||||
fun leave() { run.end(RunEnd(game.score, finished = !game.alive)); latestPlay.onLeave() }
|
||||
// Steps on the clock (Difficulty sets its pace; Normal as it always was), drawn on every frame between them.
|
||||
var sinceStep by remember { mutableLongStateOf(0L) }
|
||||
ArcadeGameLoop(loopRuns(paused, game.alive, shown = true), onStart = { sinceStep = 0L }) { _, dt ->
|
||||
if (paused || !game.alive) return@ArcadeGameLoop
|
||||
val tick = game.tickMs * 1_000_000L
|
||||
ArcadeGameLoop(loopRuns(paused, game.alive && stage == ClassicStage.Play, shown = true), onStart = { sinceStep = 0L }) { _, dt ->
|
||||
if (paused || !game.alive || stage != ClassicStage.Play) return@ArcadeGameLoop
|
||||
val tick = (game.tickMs * 1_000_000L / pace).toLong()
|
||||
sinceStep += dt
|
||||
if (sinceStep >= tick) {
|
||||
sinceStep -= tick
|
||||
before = game.body
|
||||
game = game.step(random)
|
||||
if (!game.alive) { run.end(RunEnd(game.score, finished = true)); stage = ClassicStage.Result }
|
||||
}
|
||||
progress = (sinceStep.toFloat() / tick).coerceIn(0f, 1f)
|
||||
}
|
||||
var musicOn by remember { mutableStateOf(play.setting("music")) }
|
||||
val playing = musicOn && !paused && game.alive
|
||||
val playing = musicOn && !paused && game.alive && stage == ClassicStage.Play
|
||||
LaunchedEffect(playing) { play.audio.music(R.raw.snake_theme, playing, base = .5f, gameOn = musicOn) }
|
||||
DisposableEffect(Unit) { onDispose { play.audio.stopMusic() } }
|
||||
val menuFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(paused, game.alive) { if (paused || !game.alive) menuFocus.requestFocus() else focus.requestFocus() }
|
||||
// The best as it stood while this game was played, so the new best still shows once it's been saved; Zip and Blaze cheer it.
|
||||
val bestBefore = remember(game.alive) { best }
|
||||
val newBest = game.score > bestBefore && game.score > 0
|
||||
BackHandler { if (game.alive) paused = !paused else play.onLeave() }
|
||||
Row(Modifier.fillMaxSize().background(Navy).padding(20.dp).focusRequester(focus).focusable().onPreviewKeyEvent { event ->
|
||||
val native = event.nativeKeyEvent
|
||||
if (native.action != KeyEvent.ACTION_DOWN || paused || !game.alive) return@onPreviewKeyEvent false
|
||||
val direction = when (native.keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_UP -> SnakeDirection.Up
|
||||
KeyEvent.KEYCODE_DPAD_DOWN -> SnakeDirection.Down
|
||||
KeyEvent.KEYCODE_DPAD_LEFT -> SnakeDirection.Left
|
||||
KeyEvent.KEYCODE_DPAD_RIGHT -> SnakeDirection.Right
|
||||
LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == ClassicStage.Play && !paused) { paused = true }
|
||||
|
||||
if (stage == ClassicStage.Title) {
|
||||
ClassicTitle(gameDef, ArcadeLook.comet(0), OrbCharacter.Blaze.colour, "Stars! I'm starving!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"),
|
||||
timed = true, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
note = "He speeds up with every star, and the sky changes every hundred points.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, pause = { paused = true }) { key, native ->
|
||||
if (native.action != KeyEvent.ACTION_DOWN) return@gameKeys key != ArcadeKey.Other
|
||||
val direction = when (key) {
|
||||
ArcadeKey.Up -> SnakeDirection.Up
|
||||
ArcadeKey.Down -> SnakeDirection.Down
|
||||
ArcadeKey.Left -> SnakeDirection.Left
|
||||
ArcadeKey.Right -> SnakeDirection.Right
|
||||
else -> null
|
||||
}
|
||||
if (direction != null) game = game.turn(direction)
|
||||
direction != null
|
||||
}, horizontalArrangement = Arrangement.spacedBy(20.dp)) {
|
||||
Column(Modifier.width(190.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("COMET TRAIL", color = Honey, fontFamily = Marquee, fontSize = 30.sp, lineHeight = 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 = Ink, fontFamily = Marquee, fontSize = 36.sp)
|
||||
Text("BEST", color = Muted, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp)
|
||||
Text(maxOf(best, game.score).toString(), color = Ink, fontFamily = Marquee, fontSize = 36.sp)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("◄►▲▼ Steer", color = Muted, fontSize = 13.sp)
|
||||
Text("Back Pause", color = Muted, fontSize = 13.sp)
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight().background(Color(0xFF050E2A)).border(2.dp, Blue), contentAlignment = Alignment.Center) {
|
||||
// Reduce motion: the scene changes at once instead of a slow crossfade.
|
||||
Crossfade(snakeBackdrop(game.score), animationSpec = tween(if (Motion.reduce) 0 else 1500), label = "backdrop") { scene -> SnakeBackdrop(scene, Modifier.fillMaxSize()) }
|
||||
SnakeField(game, Modifier.fillMaxSize().padding(6.dp), before, progress)
|
||||
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 && newBest) CastCheer()
|
||||
if (!game.alive) Text(if (newBest) "New best: ${game.score}" else "Score: ${game.score}", color = Ink, fontSize = 16.sp)
|
||||
OrbitButton(if (game.alive) "Carry on" else "Play again", Modifier.width(200.dp).focusRequester(menuFocus), onClick = {
|
||||
if (!game.alive) { game = SnakeGame.start(30, 22, random); before = null; progress = 1f }
|
||||
paused = false
|
||||
})
|
||||
OrbitButton("Music: ${if (musicOn) "On" else "Off"}", Modifier.width(200.dp), onClick = { musicOn = !musicOn; play.setSetting("music", musicOn) })
|
||||
OrbitButton("Leave the game", Modifier.width(200.dp), onClick = play.onLeave)
|
||||
}
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
// The sky behind changes every hundred points, as it always has, through the Arcade's collection (or stays on the one chosen).
|
||||
Crossfade(ArcadeLook.comet(game.score), animationSpec = tween(if (Motion.reduce) 0 else 1500), label = "backdrop") { sky -> ArcadeBackdropLayer(sky) }
|
||||
ClassicPlayFrame(null, keys, footer = listOf(Control("◀▶▲▼", "Steer Blaze"), Control("Back", "Pause")), note = "Two quick turns? Both count", hud = {
|
||||
HudLabel("SCORE"); HudValue("%,d".format(game.score))
|
||||
HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score)))
|
||||
Spacer(Modifier.height(6.dp))
|
||||
HudLabel("TAIL"); HudValue("${game.body.size - 1}")
|
||||
}) {
|
||||
SnakeField(game, Modifier.fillMaxSize().classicPanel().padding(6.dp), before, progress)
|
||||
}
|
||||
if (stage == ClassicStage.Result) ClassicResult(gameDef, "COMET TRAIL · ${game.body.size - 1} TAIL PUFFS", "SCORE", "%,d".format(game.score),
|
||||
newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title), detail = null,
|
||||
cheer = Mascot.Zip, onAgain = ::startRun, onBack = ::leave)
|
||||
if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Comet Trail · ${"%,d".format(game.score)}",
|
||||
onResume = { paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false)); startRun() }, onExit = ::leave,
|
||||
sound = if (musicOn) "Music on" else "Music off", onSound = { musicOn = !musicOn; latestPlay.setSetting("music", musicOn) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,9 +142,9 @@ internal class OrbitSettings(context: Context) {
|
||||
var arcadeSounds: Boolean
|
||||
get() = saved.getBoolean("arcade_sounds", true)
|
||||
set(value) { saved.edit().putBoolean("arcade_sounds", value).apply() }
|
||||
/** The Arcade backdrop behind every game ([ArcadeBackdrop]); Night Sky until one is chosen. */
|
||||
/** The Arcade backdrop chosen for every game ([ArcadeBackdrop]), or "Auto" for each game's own. */
|
||||
var arcadeBackdrop: String
|
||||
get() = saved.getString("arcade_backdrop", null) ?: ArcadeBackdrop.NightSky.name
|
||||
get() = saved.getString("arcade_backdrop", null) ?: "Auto"
|
||||
set(value) { saved.edit().putString("arcade_backdrop", value).apply() }
|
||||
var reduceMotion: Boolean
|
||||
get() = saved.getBoolean("reduce_motion", false)
|
||||
|
||||
@@ -119,8 +119,8 @@ internal object ArcadeGames {
|
||||
listOf(Control("◀▶▲▼", "Move"), Control("OK", "Turn a card"), BackPause), "In as few moves as you can.") { PairsScreen(it) }
|
||||
val Patience: ArcadeGame = GameDef("Patience", "Patience", "Solitaire, with Ollie on every card", "Build each suit home from ace to king.", Mascot.Ollie,
|
||||
kidsSuitable = true, original = false, launchable = true, ScoreKind.Wins, keepsLevels = false, legacyRecordKey = "patience_wins",
|
||||
listOf(Control("◀▶▲▼", "Point"), Control("OK", "Pick up / put down"), Control("▲▼", "In a column: how many"), Control("Menu", "Send a card home"), Control("Back", "Put back / pause")),
|
||||
"Klondike, one card at a time.") { PatienceScreen(it) }
|
||||
listOf(Control("◀▶▲▼", "Point"), Control("OK", "Pick up / put down"), Control("OK twice", "Send a card home"), Control("Back", "Put back, or pause")),
|
||||
"Klondike, one card at a time: build each suit home, ace to king.") { PatienceScreen(it) }
|
||||
|
||||
val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids)
|
||||
val classics = listOf(OrbMan, Blast, Sky, Snake, Blocks, Bricks, Pairs, Patience)
|
||||
|
||||
@@ -39,6 +39,37 @@ internal fun Modifier.onBackKey(enabled: Boolean = true, action: () -> Unit): Mo
|
||||
/** What a key means in play: Back (and play/pause) always pause, never leave. */
|
||||
internal fun pausesGame(key: ArcadeKey) = key == ArcadeKey.Back || key == ArcadeKey.PlayPause
|
||||
|
||||
/** What a Back press does in play (Paul, 9 November 2026: "Fix Back properly, not just universally"). */
|
||||
internal enum class BackStep { None, Cancel, Pause }
|
||||
|
||||
/**
|
||||
* Back, by context, the one rule every game follows: it undoes the innermost thing in hand first (Patience's held card,
|
||||
* Blast Off's shape chosen in the tray), and only pauses when nothing is in hand. Play/pause always pauses. Only the
|
||||
* press acts; its repeats and its release do nothing ([backPressActs]).
|
||||
*/
|
||||
internal fun backStep(key: ArcadeKey, down: Boolean, repeatCount: Int, active: Boolean): BackStep = when {
|
||||
key != ArcadeKey.Back && key != ArcadeKey.PlayPause -> BackStep.None
|
||||
!backPressActs(down, repeatCount) -> BackStep.None
|
||||
key == ArcadeKey.Back && active -> BackStep.Cancel
|
||||
else -> BackStep.Pause
|
||||
}
|
||||
|
||||
/**
|
||||
* A game's keys in play, with Back by context ([backStep]) caught before Compose spends it on focus. [active] says whether
|
||||
* something is in hand, [cancel] puts it back, [pause] pauses; every other key goes to [onKey] (true when it was used).
|
||||
* Back and play/pause are always swallowed here, so nothing else hears them.
|
||||
*/
|
||||
internal fun Modifier.gameKeys(enabled: Boolean, active: () -> Boolean = { false }, cancel: () -> Unit = {}, pause: () -> Unit,
|
||||
onKey: (ArcadeKey, KeyEvent) -> Boolean): Modifier = onPreviewKeyEvent { e ->
|
||||
val n = e.nativeKeyEvent
|
||||
if (!enabled) return@onPreviewKeyEvent false
|
||||
val key = arcadeKey(n.keyCode)
|
||||
if (key == ArcadeKey.Back || key == ArcadeKey.PlayPause) {
|
||||
when (backStep(key, n.action == KeyEvent.ACTION_DOWN, n.repeatCount, active())) { BackStep.Cancel -> cancel(); BackStep.Pause -> pause(); BackStep.None -> {} }
|
||||
true
|
||||
} else onKey(key, n)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holding a button on the remote repeats it. For moves that's wanted, but for one-shot actions (Block Drop's hard drop,
|
||||
* Blast Off's place) a held OK would drop or place again and again (audit finding 8). The guard lets a one-shot key act
|
||||
|
||||
@@ -238,9 +238,9 @@ internal fun ArcadeSettingsPage(profile: Profile, data: ArcadeProfileData, onCha
|
||||
ToggleRow("Reduce flashing", calm, detail = "No flashes of the screen; hits only tint the sprite") { onChange("reduceFlashing", !calm) }
|
||||
}
|
||||
SettingsCard("Look", "★") {
|
||||
var look by remember { mutableStateOf(ArcadeLook.backdrop) }
|
||||
ArcadeButton("Backdrop", Modifier.fillMaxWidth(), detail = look.title, height = 26.dp, onClick = { ArcadeLook.next(settings); look = ArcadeLook.backdrop })
|
||||
Text("Behind every game, for everyone on this TV.", color = ArcadeColours.Muted, fontSize = 11.sp, modifier = Modifier.padding(start = 10.dp))
|
||||
var look by remember { mutableStateOf(ArcadeLook.title) }
|
||||
ArcadeButton("Backdrop", Modifier.fillMaxWidth(), detail = look, height = 26.dp, onClick = { ArcadeLook.next(settings); look = ArcadeLook.title })
|
||||
Text("Each Classic has its own, or choose one for every game. For everyone on this TV.", color = ArcadeColours.Muted, fontSize = 11.sp, modifier = Modifier.padding(start = 10.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,8 @@ internal fun ArcadePauseMenu(game: ArcadeGame, line: String, onResume: () -> Uni
|
||||
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
|
||||
BackHandler(onBack = onResume)
|
||||
ArcadeScrim {
|
||||
Column(Modifier.width(210.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(12.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(12.dp)).padding(16.dp),
|
||||
// Back caught here as well: on the TV a focused button would otherwise spend it moving focus (menus go up one level).
|
||||
Column(Modifier.width(210.dp).onBackKey(action = onResume).background(ArcadeColours.PanelDeep, RoundedCornerShape(12.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(12.dp)).padding(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text("PAUSED", color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 30.sp)
|
||||
Text(line, color = ArcadeColours.Muted, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
@@ -133,7 +134,7 @@ internal fun HowToPlayCard(game: ArcadeGame, firstRun: Boolean, everyTime: Boole
|
||||
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
|
||||
BackHandler(onBack = onBack)
|
||||
ArcadeScrim {
|
||||
Row(Modifier.padding(horizontal = 52.dp, vertical = 30.dp).fillMaxWidth().background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp))
|
||||
Row(Modifier.padding(horizontal = 52.dp, vertical = 30.dp).fillMaxWidth().onBackKey(action = onBack).background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp))
|
||||
.border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(24.dp), horizontalArrangement = Arrangement.spacedBy(28.dp)) {
|
||||
// A plain drawing of the remote, its ring lit.
|
||||
Canvas(Modifier.width(76.dp).height(210.dp)) {
|
||||
@@ -183,7 +184,7 @@ internal fun ArcadeConfirm(icon: String, title: String, detail: String, confirm:
|
||||
LaunchedEffect(Unit) { runCatching { cancel.requestFocus() } }
|
||||
BackHandler(onBack = onCancel)
|
||||
ArcadeScrim {
|
||||
Column(Modifier.width(306.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(12.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(12.dp)).padding(18.dp),
|
||||
Column(Modifier.width(306.dp).onBackKey(action = onCancel).background(ArcadeColours.PanelDeep, RoundedCornerShape(12.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(12.dp)).padding(18.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(Modifier.size(28.dp).background(ArcadeColours.Panel, CircleShape), contentAlignment = Alignment.Center) { Text(icon, color = ArcadeColours.Ink, fontSize = 14.sp) }
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package tv.orbit.classic.arcade
|
||||
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
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.Offset
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shadow
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.tv.material3.Text
|
||||
import tv.orbit.classic.Anton
|
||||
import tv.orbit.classic.ArcadeBackdrop
|
||||
import tv.orbit.classic.ArcadeBackdropLayer
|
||||
|
||||
/**
|
||||
* The Classics' family look (Paul, 9 November 2026: "they all have to look like same library of games you know from
|
||||
* Orbit"): the same title, play frame and result as the Orbit Originals (Stage B frames 30 to 33), in the Arcade's own
|
||||
* colours and Anton, with the remote's keys as key caps. The games keep their own rules; this is only how they're shown.
|
||||
*/
|
||||
internal enum class ClassicStage { Title, Play, Result }
|
||||
|
||||
/**
|
||||
* Difficulty for the Classics that run on a clock: Normal is each game exactly as it always was; Gentle runs it a fifth
|
||||
* slower, Tricky a fifth quicker. The puzzles have no clock, so it doesn't change them.
|
||||
*/
|
||||
internal fun classicPace(d: Difficulty) = when (d) { Difficulty.Gentle -> .8f; Difficulty.Normal -> 1f; Difficulty.Tricky -> 1.2f }
|
||||
|
||||
/** A HUD label, at the kit's size (about 17 sp on the 1080p frames, never under 13). */
|
||||
@Composable
|
||||
internal fun HudLabel(text: String, modifier: Modifier = Modifier, colour: Color = ArcadeColours.Muted) =
|
||||
Text(text, modifier, color = colour, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
|
||||
/** A HUD number, in Anton. */
|
||||
@Composable
|
||||
internal fun HudValue(text: String, colour: Color = ArcadeColours.Ink) = Text(text, color = colour, fontFamily = Anton, fontSize = 30.sp, maxLines = 1)
|
||||
|
||||
/** The dark panel a board sits on, over the backdrop. */
|
||||
internal fun Modifier.classicPanel(): Modifier = background(ArcadeColours.PanelDeep.copy(alpha = .9f), RoundedCornerShape(11.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(11.dp))
|
||||
|
||||
/** A white speech bubble, as the cast speak in every Original. */
|
||||
@Composable
|
||||
internal fun SpeechBubble(text: String, modifier: Modifier = Modifier) = Text(text, modifier.background(ArcadeColours.Ink, RoundedCornerShape(12.dp)).padding(horizontal = 10.dp, vertical = 6.dp),
|
||||
color = ArcadeColours.Night, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center)
|
||||
|
||||
@Composable
|
||||
private fun Chip(text: String, fill: Color) = Text(text, Modifier.background(fill, RoundedCornerShape(10.dp)).padding(horizontal = 8.dp), color = ArcadeColours.Night, fontSize = 12.sp, fontWeight = FontWeight.Bold)
|
||||
|
||||
/**
|
||||
* A Classic's title (frame 30's layout): AN ORBIT ARCADE CLASSIC, the name big in Anton, its host with a word, Play, How to
|
||||
* Play and Back to Arcade, the keys at a glance, and the player's own numbers. [timed] says whether Difficulty changes it.
|
||||
* [mode] is shown as a chip; a game with more than one ([modes]) gets a Mode button that steps through them, each with its
|
||||
* own scores.
|
||||
*/
|
||||
@Composable
|
||||
internal fun ClassicTitle(game: ArcadeGame, backdrop: ArcadeBackdrop, accent: Color, hostLine: String, stats: List<Pair<String, String>>, timed: Boolean,
|
||||
difficulty: Difficulty, refocus: Boolean, onPlay: () -> Unit, onHowTo: () -> Unit, onBack: () -> Unit,
|
||||
mode: String = "Classic", modes: Int = 1, onMode: () -> Unit = {}, playLabel: String = "Play", note: String? = null) {
|
||||
val play = remember { FocusRequester() }
|
||||
LaunchedEffect(refocus) { if (refocus) runCatching { play.requestFocus() } }
|
||||
Box(Modifier.fillMaxSize().onBackKey(action = onBack)) {
|
||||
BackHandler(onBack = onBack)
|
||||
ArcadeBackdropLayer(backdrop)
|
||||
Column(Modifier.fillMaxSize().padding(start = 48.dp, end = 48.dp, top = 24.dp, bottom = 12.dp)) {
|
||||
Row(Modifier.fillMaxWidth().weight(1f)) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text("AN ORBIT ARCADE CLASSIC", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 5.sp)
|
||||
Text(game.title.uppercase(), Modifier.padding(top = 2.dp), color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 76.sp, maxLines = 1,
|
||||
style = TextStyle(shadow = Shadow(accent, Offset(5f, 5f), 0f)))
|
||||
Text(game.tagline, color = ArcadeColours.Ink, fontSize = 18.sp, fontWeight = FontWeight.SemiBold)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(game.blurb, Modifier.widthIn(max = 460.dp), color = ArcadeColours.Muted, fontSize = 15.sp)
|
||||
}
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
SpeechBubble(hostLine)
|
||||
Canvas(Modifier.size(80.dp)) { drawMascot(game.mascot, center, size.minDimension * .36f) }
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
Column(Modifier.width(210.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
ArcadeButton(playLabel, Modifier.fillMaxWidth().focusRequester(play), icon = "▶", primary = true, height = 34.dp, onClick = onPlay)
|
||||
if (modes > 1) ArcadeButton("Mode", Modifier.fillMaxWidth(), icon = "◆", detail = mode, height = 34.dp, onClick = onMode)
|
||||
ArcadeButton("How to Play", Modifier.fillMaxWidth(), icon = "?", height = 34.dp, onClick = onHowTo)
|
||||
ArcadeButton("Back to Arcade", Modifier.fillMaxWidth(), icon = "←", height = 34.dp, onClick = onBack)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The keys at a glance, and what the game is about.
|
||||
Row(Modifier.fillMaxWidth().classicPanel().padding(14.dp), horizontalArrangement = Arrangement.spacedBy(28.dp)) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
game.controls.forEach { c ->
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { Box(Modifier.width(84.dp)) { KeyCap(c.keys) }; Text(c.action, color = ArcadeColours.Ink, fontSize = 15.sp) }
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text("HOW IT GOES", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp)
|
||||
Text(game.goal, color = ArcadeColours.Ink, fontSize = 15.sp)
|
||||
if (note != null) Text(note, color = ArcadeColours.Muted, fontSize = 14.sp)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(10.dp))
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp)) {
|
||||
stats.forEach { (label, value) -> Row { Text("$label ", color = ArcadeColours.Muted, fontSize = 14.sp); Text(value, color = ArcadeColours.Ink, fontSize = 14.sp, fontWeight = FontWeight.Bold) } }
|
||||
Chip(mode, ArcadeColours.Yellow)
|
||||
Chip(if (timed) difficulty.title else "No timer", ArcadeColours.Cyan)
|
||||
}
|
||||
Spacer(Modifier.height(8.dp))
|
||||
KeyFooter(listOf(Control("▲▼", "Choose"), Control("OK", "Select"), Control("Back", "Arcade home")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The play frame: the backdrop, the HUD down the left, the board, an optional column on the right, and the keys along the
|
||||
* foot ([backdrop] null when the game draws its own behind). [keys] is the game's key handling (focus and [gameKeys]); it sits on the whole frame.
|
||||
*/
|
||||
@Suppress("ModifierParameter") // [keys] is the frame's key handling, given by every game, not a layout modifier
|
||||
@Composable
|
||||
internal fun ClassicPlayFrame(backdrop: ArcadeBackdrop?, keys: Modifier, footer: List<Control>, note: String? = null,
|
||||
hud: @Composable ColumnScope.() -> Unit, side: (@Composable ColumnScope.() -> Unit)? = null, board: @Composable BoxScope.() -> Unit) {
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
// Null when the game draws its own behind (Comet Trail crossfades between skies).
|
||||
if (backdrop != null) ArcadeBackdropLayer(backdrop)
|
||||
Column(Modifier.fillMaxSize().then(keys).padding(start = 32.dp, end = 32.dp, top = 20.dp, bottom = 10.dp)) {
|
||||
Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(18.dp)) {
|
||||
Column(Modifier.width(176.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(2.dp), content = hud)
|
||||
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center, content = board)
|
||||
if (side != null) Column(Modifier.width(140.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(4.dp), content = side)
|
||||
}
|
||||
Spacer(Modifier.height(6.dp))
|
||||
KeyFooter(footer, note = note)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The result (frame 33's layout): the game and how far it got, NEW BEST when it is, the number big, the best before it, a
|
||||
* line of what happened, then Play Again (first) and Back to Arcade. The host on the left, a cheering friend on the right.
|
||||
* [extra] is one more button where a game has one (Skydoku's New puzzle).
|
||||
*/
|
||||
@Composable
|
||||
internal fun ClassicResult(game: ArcadeGame, kicker: String, label: String, value: String, newBest: Boolean, previous: String, detail: String?,
|
||||
onAgain: () -> Unit, onBack: () -> Unit, cheer: Mascot = Mascot.Zip, againLabel: String = "Play Again",
|
||||
extra: Pair<String, () -> Unit>? = null, heading: String? = null) {
|
||||
val first = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
|
||||
BackHandler(onBack = onBack)
|
||||
Box(Modifier.fillMaxSize().onBackKey(action = onBack).background(ArcadeColours.Night.copy(alpha = .82f)), contentAlignment = Alignment.Center) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(16.dp)) {
|
||||
Canvas(Modifier.size(100.dp)) { drawMascot(game.mascot, center, size.minDimension * .36f) }
|
||||
Column(Modifier.width(if (extra != null) 600.dp else 520.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text(kicker, color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
if (heading != null) Text(heading, color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 30.sp)
|
||||
if (newBest) Text("NEW BEST", Modifier.background(ArcadeColours.Pink, RoundedCornerShape(14.dp)).padding(horizontal = 14.dp, vertical = 2.dp), color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.Bold)
|
||||
Text(label, color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 2.sp)
|
||||
Text(value, color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 54.sp, maxLines = 1)
|
||||
Text(previous, color = ArcadeColours.Ink, fontSize = 14.sp)
|
||||
if (detail != null) Text(detail, color = ArcadeColours.Muted, fontSize = 13.sp, textAlign = TextAlign.Center)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
ArcadeButton(againLabel, Modifier.width(160.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = onAgain)
|
||||
if (extra != null) ArcadeButton(extra.first, Modifier.width(160.dp), icon = "✦", height = 34.dp, onClick = extra.second)
|
||||
ArcadeButton("Back to Arcade", Modifier.width(200.dp), icon = "←", height = 34.dp, onClick = onBack)
|
||||
}
|
||||
}
|
||||
Canvas(Modifier.size(100.dp)) { drawMascot(cheer, center, size.minDimension * .36f) }
|
||||
}
|
||||
KeyFooter(listOf(Control("◀▶", "Choose"), Control("OK", "Select"), Control("Back", "Arcade home")), Modifier.align(Alignment.BottomStart).padding(start = 24.dp, end = 24.dp, bottom = 10.dp))
|
||||
}
|
||||
}
|
||||
|
||||
/** "Previous best 1,230", or the first-score line. */
|
||||
internal fun previousLine(kind: ScoreKind, before: Int, title: String): String =
|
||||
if (before > 0) "Previous best ${formatScore(kind, before)}" else "Your first $title score"
|
||||
@@ -26,13 +26,13 @@ class OrbManTest {
|
||||
g = play(g, OrbGame.READY_TICKS + g.playerEvery)
|
||||
assertEquals(OrbPos(maze.start.x - 1, maze.start.y), g.player.pos)
|
||||
assertEquals(10, g.score); assertTrue(OrbEvent.Star in g.events || g.score == 10)
|
||||
// Up is a wall at (8, 11): he carries on left, and goes up as soon as there's room, at (7, 11).
|
||||
val at = OrbPos(8, 11)
|
||||
// Up is a wall at (2, 11): he carries on left, and goes up as soon as there's room, at (1, 11).
|
||||
val at = OrbPos(2, 11)
|
||||
g = g.copy(player = OrbMover(at, at, OrbDir.Left, g.tick), wanted = OrbDir.Up)
|
||||
g = play(g, g.playerEvery)
|
||||
assertEquals(OrbPos(7, 11), g.player.pos); assertEquals(OrbDir.Left, g.player.dir)
|
||||
assertEquals(OrbPos(1, 11), g.player.pos); assertEquals(OrbDir.Left, g.player.dir)
|
||||
g = play(g, g.playerEvery)
|
||||
assertEquals(OrbPos(7, 10), g.player.pos); assertEquals(OrbDir.Up, g.player.dir)
|
||||
assertEquals(OrbPos(1, 10), g.player.pos); assertEquals(OrbDir.Up, g.player.dir)
|
||||
}
|
||||
|
||||
@Test fun aPowerHexagonFrightensTheRocksAndCatchingOneScores() {
|
||||
@@ -83,4 +83,15 @@ class OrbManTest {
|
||||
}
|
||||
assertTrue(g.alive); assertEquals(4, most)
|
||||
}
|
||||
|
||||
@Test fun noWallStandsOnItsOwnAndNoCorridorIsADeadEnd() {
|
||||
// Paul, 9 November 2026: "weird pillars or dots seem separate from the maze". Every wall joins another; every corridor goes on.
|
||||
for (y in 0 until maze.height) for (x in 0 until maze.width) {
|
||||
val p = OrbPos(x, y)
|
||||
val around = OrbDir.entries.map { OrbPos(x + it.dx, y + it.dy) }.filter { it.x in 0 until maze.width && it.y in 0 until maze.height }
|
||||
if (maze.wall(p)) assertTrue("lone wall at $p", around.any { maze.wall(it) })
|
||||
else if (!maze.door(p) && !maze.den(p)) assertTrue("dead end at $p", OrbDir.entries.count { d -> maze.step(p, d).let { n -> n.y in 0 until maze.height && !maze.wall(n) && !maze.door(n) && !maze.den(n) } } >= 2)
|
||||
}
|
||||
assertTrue(maze.walls.count { it } == maze.rows.sumOf { r -> r.count { it == '#' } })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,46 @@ class PairsPatienceTest {
|
||||
|
||||
@Test fun aRunMovesTogetherAndBackPutsItDown() {
|
||||
val g = game(6 to listOf(PlayingCard(10, 1), PlayingCard(9, 0), PlayingCard(8, 2)), 7 to listOf(PlayingCard(11, 3)))
|
||||
val picked = g.point(6).steer(0, -1).steer(0, -1)
|
||||
assertEquals(3, picked.depth)
|
||||
val moved = picked.press().point(7).press()
|
||||
// A column is picked up whole; on the black jack only the red 10 and what's on it fit, so all three go.
|
||||
val picked = g.point(6).press()
|
||||
assertEquals(6 to 3, picked.held)
|
||||
val moved = picked.point(7).press()
|
||||
assertEquals(4, moved.piles[7].size); assertTrue(moved.piles[6].isEmpty())
|
||||
assertNull(g.point(6).press().drop().held)
|
||||
assertTrue(game(*HOMES.map { h -> h to (1..13).map { PlayingCard(it, h - 2) } }.toTypedArray()).won)
|
||||
}
|
||||
|
||||
@Test fun onlyAsManyAsFitMoveAndTheRestStay() {
|
||||
// Red 10, black 9, red 8 face up, onto a red 9: none of them fits, so nothing moves, the card stays in hand and it's refused.
|
||||
val g = game(6 to listOf(PlayingCard(10, 1), PlayingCard(9, 0), PlayingCard(8, 2)), 7 to listOf(PlayingCard(9, 1)))
|
||||
val refused = g.point(6).press().point(7).press()
|
||||
assertEquals(g.piles, refused.piles); assertEquals(1, refused.refusals); assertNotNull(refused.held)
|
||||
// Onto a black 9 only the red 8 fits: it moves on its own and the rest stay.
|
||||
val two = game(6 to listOf(PlayingCard(10, 1), PlayingCard(9, 0), PlayingCard(8, 2)), 7 to listOf(PlayingCard(9, 3)))
|
||||
val one = two.point(6).press().point(7).press()
|
||||
assertEquals(listOf(PlayingCard(9, 3), PlayingCard(8, 2)), one.piles[7]); assertEquals(2, one.piles[6].size)
|
||||
}
|
||||
|
||||
@Test fun upReachesTheTopRowInOnePressAndOkTwiceSendsHome() {
|
||||
val g = game(6 to listOf(PlayingCard(5, 0, false), PlayingCard(10, 1), PlayingCard(9, 0), PlayingCard(8, 2)), 12 to listOf(PlayingCard(1, 3)))
|
||||
assertEquals(STOCK, g.point(6).steer(0, -1).pile)
|
||||
assertEquals(5, g.point(12).steer(0, -1).pile)
|
||||
assertEquals(6, g.point(STOCK).steer(0, 1).pile)
|
||||
// The ace: OK picks it up, OK again on the same column sends it home.
|
||||
val home = g.point(12).press().press()
|
||||
assertEquals(listOf(PlayingCard(1, 3)), home.piles[2]); assertNull(home.held); assertEquals(1, home.moves) // the first empty home pile
|
||||
// A card with nowhere to go goes back where it was on the second OK.
|
||||
val back = g.point(6).press().press()
|
||||
assertNull(back.held); assertEquals(g.piles, back.piles)
|
||||
// The Menu key still sends home where there is one; with nothing to send it says so.
|
||||
assertEquals(1, g.point(12).sendHome().piles[2].size)
|
||||
assertEquals(1, g.point(6).sendHome().refusals)
|
||||
}
|
||||
|
||||
@Test fun longColumnsAlwaysFitTheirSpace() {
|
||||
// Six face-down and thirteen face-up cards in 340 dp, cards 104 tall.
|
||||
val step = patienceSteps(6, 13, 340f, 104f)
|
||||
assertTrue(104f + 6 * 8f + 12 * step <= 340f + .01f || step == 12f)
|
||||
assertEquals(26f, patienceSteps(0, 3, 400f, 104f), .01f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,25 @@ class SnakeGameTest {
|
||||
assertEquals(3, snakeBackdrop(300))
|
||||
assertEquals(0, snakeBackdrop(400))
|
||||
}
|
||||
|
||||
@Test fun aSecondQuickTurnIsKeptForTheNextStep() {
|
||||
// Heading right: up then left pressed within one step. Up is taken now, left on the step after: a tight U-turn works.
|
||||
val random = java.util.Random(3)
|
||||
var g = game(3 to 5, 2 to 5).turn(SnakeDirection.Up).turn(SnakeDirection.Left)
|
||||
assertEquals(SnakeDirection.Left, g.queued)
|
||||
g = g.step(random)
|
||||
assertEquals(SnakeCell(3, 4), g.body.first()); assertEquals(SnakeDirection.Left, g.wanted)
|
||||
g = g.step(random)
|
||||
assertEquals(SnakeCell(2, 4), g.body.first())
|
||||
// A queued turn can't reverse the one before it.
|
||||
assertNull(game(3 to 5, 2 to 5).turn(SnakeDirection.Up).turn(SnakeDirection.Down).queued)
|
||||
}
|
||||
|
||||
@Test fun foodIsPickedFromTheFreeSquaresAsBefore() {
|
||||
val body = listOf(SnakeCell(0, 0), SnakeCell(1, 0))
|
||||
val r1 = java.util.Random(11); val r2 = java.util.Random(11)
|
||||
val old = ((0 until 4).flatMap { y -> (0 until 5).map { x -> SnakeCell(x, y) } } - body.toSet()).let { it[r2.nextInt(it.size)] }
|
||||
assertEquals(old, SnakeGame.nextFood(5, 4, body, r1))
|
||||
assertNull(SnakeGame.nextFood(1, 2, listOf(SnakeCell(0, 0), SnakeCell(0, 1)), r1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package tv.orbit.classic.arcade
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import tv.orbit.classic.ArcadeBackdrop
|
||||
import tv.orbit.classic.BlastGame
|
||||
import tv.orbit.classic.PatienceGame
|
||||
import tv.orbit.classic.PlayingCard
|
||||
|
||||
/**
|
||||
* Paul, 9 November 2026: "Fix Back properly, not just universally. In Patience, pressing Back while holding a card should
|
||||
* cancel that action. Pressing Back when nothing is held should pause. The same principle should apply to other games with
|
||||
* active selections."
|
||||
*/
|
||||
class BackByContextTest {
|
||||
@Test fun backCancelsWhatIsInHandFirstAndOnlyThenPauses() {
|
||||
assertEquals(BackStep.Cancel, backStep(ArcadeKey.Back, down = true, repeatCount = 0, active = true))
|
||||
assertEquals(BackStep.Pause, backStep(ArcadeKey.Back, down = true, repeatCount = 0, active = false))
|
||||
// Play/pause always pauses, even with something in hand.
|
||||
assertEquals(BackStep.Pause, backStep(ArcadeKey.PlayPause, down = true, repeatCount = 0, active = true))
|
||||
// Only the press acts: not its repeats, not its release.
|
||||
assertEquals(BackStep.None, backStep(ArcadeKey.Back, down = true, repeatCount = 1, active = true))
|
||||
assertEquals(BackStep.None, backStep(ArcadeKey.Back, down = false, repeatCount = 0, active = false))
|
||||
assertEquals(BackStep.None, backStep(ArcadeKey.Ok, down = true, repeatCount = 0, active = true))
|
||||
}
|
||||
|
||||
@Test fun patienceBackPutsAHeldCardBackAndTheNextBackPauses() {
|
||||
val g = PatienceGame(List(13) { i -> if (i == 6) listOf(PlayingCard(7, 1)) else emptyList() })
|
||||
val held = g.point(6).press()
|
||||
assertNotNull(held.held)
|
||||
// Back with a card in hand: Cancel, which puts it back with nothing moved.
|
||||
assertEquals(BackStep.Cancel, backStep(ArcadeKey.Back, true, 0, active = held.held != null))
|
||||
val back = held.drop()
|
||||
assertNull(back.held); assertEquals(g.piles, back.piles); assertEquals(0, back.moves)
|
||||
// Nothing in hand now: the next Back pauses.
|
||||
assertEquals(BackStep.Pause, backStep(ArcadeKey.Back, true, 0, active = back.held != null))
|
||||
}
|
||||
|
||||
@Test fun blastOffBackFromTheTrayReturnsToTheBoardWithTheShapeItHad() {
|
||||
val g = BlastGame.start(java.util.Random(4))
|
||||
var inTray = g
|
||||
repeat(10) { inTray = inTray.move(0, 1) }
|
||||
assertTrue(inTray.inTray)
|
||||
assertEquals(BackStep.Cancel, backStep(ArcadeKey.Back, true, 0, active = inTray.inTray))
|
||||
val board = inTray.move(0, -1)
|
||||
assertFalse(board.inTray); assertEquals(inTray.selected, board.selected)
|
||||
assertEquals(BackStep.Pause, backStep(ArcadeKey.Back, true, 0, active = board.inTray))
|
||||
}
|
||||
|
||||
@Test fun theOtherClassicsHaveNothingInHandSoBackPauses() {
|
||||
// Star Chase, Brick Break, Block Drop and Comet Trail run on a clock; a turned card in Pairs can't be turned back; a Skydoku
|
||||
// star is placed by its one press. Each passes active = false (the default), so Back pauses.
|
||||
assertEquals(BackStep.Pause, backStep(ArcadeKey.Back, true, 0, active = false))
|
||||
}
|
||||
|
||||
@Test fun backdropsKeepAnOldChoiceAndEveryClassicHasItsOwn() {
|
||||
assertNull(ArcadeBackdrop.parse(null)); assertNull(ArcadeBackdrop.parse("NightSky")); assertNull(ArcadeBackdrop.parse("Auto"))
|
||||
assertEquals(ArcadeBackdrop.Nebula, ArcadeBackdrop.parse("Nebula"))
|
||||
assertEquals(ArcadeBackdrop.Rooftops, ArcadeBackdrop.parse("Moonrise"))
|
||||
assertEquals(ArcadeBackdrop.Teletext, ArcadeBackdrop.parse("Teletext"))
|
||||
assertNull(ArcadeBackdrop.parse("SomethingElse"))
|
||||
val defaults = ArcadeGames.classics.map { ArcadeBackdrop.forGame(it.id) }
|
||||
assertEquals(8, defaults.size)
|
||||
// Seven of the eight backdrops are a Classic's own; the eighth (Aurora) is one of Comet Trail's changing skies.
|
||||
assertEquals(ArcadeBackdrop.entries.toSet(), (defaults + ArcadeBackdrop.cometSkies).toSet())
|
||||
}
|
||||
}
|
||||
@@ -65,4 +65,25 @@ class TitleTextFitsTest {
|
||||
val caption = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(20f * 1.3f)
|
||||
for (l in tv.orbit.classic.arcade.chaos.Interludes.ALL) for (w in l.text.split(' ')) assertTrue(w, width(caption, w) < 420 - 28)
|
||||
}
|
||||
|
||||
@Test fun classicTitlesAndButtonsFitAtTheLargestFontScale() {
|
||||
// The box draws 960 × 540 dp at 720p and at 1080p alike, so one check covers both.
|
||||
// Each name in Anton at 76 sp in the title's left column: 960 less the side padding (2 × 48) and the 210 dp button column.
|
||||
val anton = Font.createFont(Font.TRUETYPE_FONT, File("src/main/res/font/anton_regular.ttf")).deriveFont(76f)
|
||||
for (g in ArcadeGames.classics) {
|
||||
val w = width(anton, g.title.uppercase())
|
||||
assertTrue("${g.title} is ${"%.0f".format(w)} dp", w <= 960.0 - 96 - 210 - 16)
|
||||
}
|
||||
val font = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(14f * 1.3f)
|
||||
val labels = listOf("▶ Play" to 210, "▶ Deal" to 210, "▶ Today's puzzle" to 210, "▶ New puzzle" to 210, "? How to Play" to 210, "← Back to Arcade" to 210,
|
||||
"▶ Play Again" to 160, "▶ Deal again" to 160, "▶ Try it again" to 160, "▶ New puzzle" to 160, "✦ New puzzle" to 160, "← Back to Arcade" to 200)
|
||||
for ((label, column) in labels) {
|
||||
val w = width(font, label)
|
||||
assertTrue("$label is ${"%.0f".format(w)} dp in $column", w <= column - 2 * 12 - 4)
|
||||
}
|
||||
// The result's three buttons (Skydoku out of hearts) fit its wider card: 600 dp less 2 × 20 padding.
|
||||
assertTrue(160 + 160 + 200 + 2 * 10 <= 600 - 40)
|
||||
// And the whole result row fits the screen: the cast either side.
|
||||
assertTrue(100 + 16 + 600 + 16 + 100 <= 960)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user