diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 6b004963..ef2f3d9a 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 296 - versionName = "0.110.13-story-p1000" + versionCode = 297 + versionName = "0.110.14-chaos" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeGames.kt b/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeGames.kt index e701e1b9..e0f81dd1 100644 --- a/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeGames.kt +++ b/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeGames.kt @@ -73,9 +73,11 @@ internal object ArcadeGames { listOf(Control("◀▶", "Move"), Control("OK", "Fire"), Control("Hold OK", "Auto-fire"), Control("▲", "Overdrive, when the meter is full"), BackPause), "Keep the Orbit signal on air: each hit costs a bar.", listOf(GameSetting("sounds", "Sound effects"))) { tv.orbit.classic.arcade.raiders.OrbiRaidersScreen(it) } + // Playable from 8 November 2026 (prototype): tv.orbit.classic.arcade.chaos. val ChannelChaos: ArcadeGame = GameDef("ChannelChaos", "Channel Chaos", "Sort the signals", "Send every signal to its channel before the screens jam.", Mascot.Ollie, - kidsSuitable = true, original = true, launchable = false, ScoreKind.Points, keepsLevels = true, legacyRecordKey = null, - listOf(Control("◀▶▲▼", "Send a signal"), Control("OK", "Bin the static"), BackPause), "Three jammed screens and the run ends.") + kidsSuitable = true, original = true, launchable = true, ScoreKind.Points, keepsLevels = true, legacyRecordKey = null, + listOf(Control("◀▶▲▼", "Send a signal"), Control("OK", "Bin the static"), BackPause), "Three jammed screens and the run ends.", + listOf(GameSetting("sounds", "Sound effects"))) { tv.orbit.classic.arcade.chaos.ChannelChaosScreen(it) } val Hive: ArcadeGame = GameDef("Hive", "BumbleHive", "Link, match, clear the hive", "Help Bumble fire flowers and clear the hive.", Mascot.Bumble, kidsSuitable = true, original = true, launchable = true, ScoreKind.Points, keepsLevels = true, legacyRecordKey = null, listOf(Control("◀▶", "Aim"), Control("OK", "Fire a flower"), Control("▼", "Swap flower"), Control("▲", "Honeybomb"), BackPause), diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChannelChaosScreen.kt b/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChannelChaosScreen.kt new file mode 100644 index 00000000..21311bc3 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChannelChaosScreen.kt @@ -0,0 +1,427 @@ +package tv.orbit.classic.arcade.chaos + +import android.view.KeyEvent +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.focusable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.rotate +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.graphics.drawscope.scale +import androidx.compose.ui.graphics.drawscope.translate +import androidx.compose.ui.graphics.painter.BitmapPainter +import androidx.compose.ui.input.key.onPreviewKeyEvent +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.imageResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.rememberTextMeasurer +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.unit.IntSize +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.Motion +import tv.orbit.classic.R +import tv.orbit.classic.arcade.ArcadeButton +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.Control +import tv.orbit.classic.arcade.HowToPlayCard +import tv.orbit.classic.arcade.KeyCap +import tv.orbit.classic.arcade.KeyFooter +import tv.orbit.classic.arcade.PauseWhenHidden +import tv.orbit.classic.arcade.RepeatGuard +import tv.orbit.classic.arcade.RunEnd +import tv.orbit.classic.arcade.RunTracker +import tv.orbit.classic.arcade.arcadeKey +import tv.orbit.classic.arcade.onBackKey +import tv.orbit.classic.arcade.raiders.FixedStep + +private enum class Stage { Title, Play, Result } + +/** What the HUD shows, each its own state, so a frame redraws the field without recomposing the words. */ +private class ChaosHud { + var frame by mutableLongStateOf(0L) + var score by mutableIntStateOf(0) + var chain by mutableIntStateOf(1) + var stage by mutableIntStateOf(1) + var jammed by mutableIntStateOf(0) + var bonusSecs by mutableIntStateOf(0) + var power by mutableStateOf(null) + var powerSecs by mutableIntStateOf(0) + var autoLeft by mutableIntStateOf(0) + var hint by mutableIntStateOf(Hint.HELLO) + var hintSide by mutableIntStateOf(0) + var phase by mutableStateOf(Phase.Playing) + var drift by mutableStateOf(false) + + fun read(s: ChaosSim) { + frame++ + score = s.score; chain = s.chain; stage = s.stage; jammed = s.jammedCount; bonusSecs = kotlin.math.ceil(s.bonus).toInt() + power = s.timedPower; powerSecs = kotlin.math.ceil(s.powerLeft).toInt(); autoLeft = s.autoLeft + hint = s.hint; hintSide = s.hintSide; phase = s.phase; drift = s.drift > 0f + } +} + +/** Ollie's hints in words (Blaze's in the bonus round). */ +internal fun hintWords(hint: Int, side: Int): String? = when (hint) { + Hint.HELLO -> "Send each signal\nto its screen!" + Hint.STATIC -> "Static next!\nPress OK to bin it." + Hint.NEARLY -> "${Chan.names[side]}'s nearly\njammed. Careful!" + Hint.JAMMED -> "${Chan.names[side]} is jammed!\nKeep the rest going." + Hint.BONUS -> "Bonus round! No static,\njust points. Go go go!" + Hint.MIXED -> "Drift's muddled one:\neither screen works!" + Hint.POWER -> "A power-up! Send it\nanywhere to catch it." + else -> null +} + +/** What a run reports when it ends. */ +internal fun chaosRunEnd(s: ChaosSim, finished: Boolean) = RunEnd(s.score, finished, "Stage ${s.stage}") + +/** + * Channel Chaos (Arcade prototype, 8 November 2026): Stage B frames 30-33 with Paul's cast and curve. Ollie keeps the + * broadcast running, Blaze hosts the bonus rounds, Drift delivers muddled signals, Bumble repairs a jammed screen. + */ +@Composable +internal fun ChannelChaosScreen(play: ArcadePlay) { + val game = ArcadeGames.ChannelChaos + val latestPlay by rememberUpdatedState(play) + val calm = Motion.reduce + val sim = remember { ChaosSim(play.difficulty, seed = 1) } + val hud = remember { ChaosHud() } + val stepper = remember { FixedStep() } + val guard = remember { RepeatGuard(setOf(ArcadeKey.Ok, ArcadeKey.Up, ArcadeKey.Down, ArcadeKey.Left, ArcadeKey.Right)) } + var stage by remember { mutableStateOf(Stage.Title) } + var paused by remember { mutableStateOf(false) } + var howTo by remember { mutableStateOf(false) } + var soundsOn by remember { mutableStateOf(play.setting("sounds")) } + var bestBefore by remember { mutableIntStateOf(play.best) } + var bestSeen by remember { mutableIntStateOf(play.best) } + var bestStage by remember { mutableIntStateOf(play.level["bestStage"]?.toIntOrNull() ?: 0) } + val tracker = remember { RunTracker { end -> bestSeen = maxOf(bestSeen, end.score); latestPlay.onRunEnd(end) } } + fun endRun(finished: Boolean) { + if (!tracker.open) return + if (sim.stage > bestStage) { bestStage = sim.stage; latestPlay.setLevel("bestStage", sim.stage.toString()) } + tracker.end(chaosRunEnd(sim, finished)) + } + DisposableEffect(Unit) { onDispose { endRun(false) } } + val density = LocalDensity.current + val measurer = rememberTextMeasurer() + val art = remember(density) { ChaosArt(density, measurer) } + val logo = ImageBitmapCache.orbitLogo() + LaunchedEffect(Unit) { play.audio.preload(R.raw.power_drift_net, R.raw.power_wide_orbit) } + + fun startRun() { + bestBefore = maxOf(latestPlay.best, bestSeen) + sim.calm = Motion.reduce + sim.newRun(latestPlay.difficulty, (System.nanoTime() and 0x7fffffff).toInt().coerceAtLeast(1)) + guard.reset(); stepper.reset(); hud.read(sim) + tracker.begin() + paused = false; stage = Stage.Play + } + fun pause() { if (stage == Stage.Play && !paused) { paused = true; guard.reset(); stepper.reset(); latestPlay.audio.pauseAll() } } + fun resume() { paused = false; guard.reset(); stepper.reset(); latestPlay.audio.resumeAll() } + fun leave() { endRun(sim.over); latestPlay.onLeave() } + + PauseWhenHidden(alive = stage == Stage.Play && !paused) { pause() } + ArcadeGameLoop(running = stage == Stage.Play && !paused) { _, dt -> + val n = stepper.ticks(dt, paused) + for (i in 0 until n) sim.step() + val ev = sim.takeEvents() + if (ev != 0) { + val audio = latestPlay.audio + if (ev and (ChaosEvents.POWER or ChaosEvents.BONUS) != 0) audio.cue(R.raw.power_drift_net, .6f, soundsOn) + if (ev and (ChaosEvents.STAGE or ChaosEvents.REPAIRED) != 0) audio.cue(R.raw.power_wide_orbit, .6f, soundsOn) + } + hud.read(sim) + if (sim.over) { endRun(true); stage = Stage.Result } + } + + val playFocus = remember { FocusRequester() } + LaunchedEffect(stage, paused) { if (stage == Stage.Play && !paused) runCatching { playFocus.requestFocus() } } + BackHandler(enabled = stage == Stage.Play && !paused) { pause() } + + when (stage) { + Stage.Title -> { + ChaosTitle(art, play.best, bestStage, play.difficulty.title, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }) + if (howTo) HowToPlayCard(game, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false }) + } + Stage.Play, Stage.Result -> { + Box(Modifier.fillMaxSize().focusRequester(playFocus).focusable().onPreviewKeyEvent { e -> + if (stage != Stage.Play || paused) return@onPreviewKeyEvent false + val n = e.nativeKeyEvent + val key = arcadeKey(n.keyCode) + val down = n.action == KeyEvent.ACTION_DOWN + // Back pauses, caught here (on the TV, Compose spends a Back moving focus, so a BackHandler alone misses it). + if (key == ArcadeKey.Back || key == ArcadeKey.PlayPause) { if (down && n.repeatCount == 0) pause(); return@onPreviewKeyEvent true } + if (key == ArcadeKey.Other || key == ArcadeKey.Menu) return@onPreviewKeyEvent false + // One press is one send: the remote's repeats of a held key never send again. + if (!guard.accept(key, down, n.repeatCount)) return@onPreviewKeyEvent true + when (key) { + ArcadeKey.Ok -> sim.ok() + ArcadeKey.Up -> sim.send(Chan.UP) + ArcadeKey.Left -> sim.send(Chan.LEFT) + ArcadeKey.Right -> sim.send(Chan.RIGHT) + ArcadeKey.Down -> sim.send(Chan.DOWN) + else -> {} + } + hud.read(sim) + true + }) { + ChaosPlay(art, logo, sim, hud, calm, play.reduceFlashing) + if (hud.phase == Phase.Interlude && stage == Stage.Play) InterludeCard(art, sim.interlude, sim.repaired) + if (stage == Stage.Result) ChaosResult(art, sim, bestBefore, onRetry = { endRun(sim.over); startRun() }, onBack = ::leave) + } + if (paused && stage == Stage.Play) ArcadePauseMenu(game, "Channel Chaos · Stage ${sim.stage} · ${"%,d".format(sim.score)}", + onResume = ::resume, onRestart = { endRun(false); startRun() }, onExit = ::leave, + sound = if (soundsOn) "Effects on" else "Effects off", onSound = { soundsOn = !soundsOn; latestPlay.setSetting("sounds", soundsOn) }) + } + } +} + +/** Orbit's own logo for the little ident: one small image (5 KB), loaded once. */ +private object ImageBitmapCache { + @Composable + fun orbitLogo() = androidx.compose.ui.graphics.ImageBitmap.imageResource(R.drawable.orbit_logo) +} + +// ---------- Title (frame 30) ---------- + +@Composable +private fun ChaosTitle(art: ChaosArt, best: Int, bestStage: Int, difficulty: String, refocus: Boolean, onPlay: () -> Unit, onHowTo: () -> Unit, onBack: () -> Unit) { + val play = remember { FocusRequester() } + LaunchedEffect(refocus) { if (refocus) runCatching { play.requestFocus() } } + Box(Modifier.fillMaxSize().onBackKey(action = onBack).background(ArcadeColours.Night)) { + BackHandler(onBack = onBack) + 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 ORIGINAL", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 5.sp) + // CHANNEL on a tilted test-card strip, CHAOS big with its letters knocked a little out of tune. + Box(Modifier.padding(top = 6.dp).rotate(-3f).background(androidx.compose.ui.graphics.Brush.horizontalGradient( + listOf(Color(0xFF35D6F2), Color(0xFFFF2EA6), Color(0xFF9BE564), Color(0xFFFFB52E), Color(0xFFA77BFF), Color(0xFFFF8A3D)))).padding(horizontal = 14.dp)) { + Text("CHANNEL", color = Color.White, fontFamily = Anton, fontSize = 34.sp, letterSpacing = 4.sp) + } + Row(Modifier.padding(top = 4.dp)) { + "CHAOS".forEachIndexed { i, ch -> + val dy = intArrayOf(0, 4, -3, 3, -1)[i]; val rot = floatArrayOf(-2f, 2f, -1f, 2f, -2f)[i] + Text(ch.toString(), Modifier.offset(y = dy.dp).rotate(rot).padding(end = 6.dp), color = Color(0xFFF5F7FF), fontFamily = Anton, fontSize = 86.sp, + style = TextStyle(shadow = Shadow(Color(0xFFFF4FA3), Offset(5f, 5f), 0f))) + } + } + } + Column(horizontalAlignment = Alignment.End) { + Row(verticalAlignment = Alignment.CenterVertically) { + Text("I'm your host!\nReady to tune in?", Modifier.background(ArcadeColours.Ink, RoundedCornerShape(12.dp)).padding(horizontal = 12.dp, vertical = 6.dp), + color = ArcadeColours.Night, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.Center) + Canvas(Modifier.size(80.dp)) { drawImage(art.faces[Speaker.Ollie.ordinal], IntOffset.Zero, art.faceSize, IntOffset.Zero, IntSize(size.width.toInt(), size.height.toInt())) } + } + Spacer(Modifier.height(16.dp)) + Column(Modifier.width(210.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { + ArcadeButton("Play", Modifier.fillMaxWidth().focusRequester(play), icon = "▶", primary = true, height = 34.dp, onClick = onPlay) + ArcadeButton("How to Play", Modifier.fillMaxWidth(), icon = "?", height = 34.dp, onClick = onHowTo) + ArcadeButton("Back to Arcade", Modifier.fillMaxWidth(), icon = "←", height = 34.dp, onClick = onBack) + } + } + } + // How it works, at a glance: the chute and its four screens in miniature. + Row(Modifier.fillMaxWidth().height(170.dp).background(ArcadeColours.PanelDeep.copy(alpha = .94f), RoundedCornerShape(11.dp)) + .border(1.dp, ArcadeColours.Line, RoundedCornerShape(11.dp)).padding(14.dp), horizontalArrangement = Arrangement.spacedBy(24.dp)) { + Canvas(Modifier.width(220.dp).fillMaxHeight()) { + val k = size.height / 300f + scale(k, k, Offset.Zero) { + translate(110f / k - 60f, 0f) { + with(art) { + for (side in 0 until Chan.SCREENS) { + val dx = floatArrayOf(0f, -100f, 100f, 0f)[side]; val dy = floatArrayOf(-100f, 0f, 0f, 100f)[side] + drawRoundRect(ChaosColours.TvBody, Offset(60f + dx - 50f, 150f + dy - 32f), androidx.compose.ui.geometry.Size(100f, 64f), androidx.compose.ui.geometry.CornerRadius(10f)) + drawRoundRect(ChaosColours.mixed(ChaosColours.channel[side]), Offset(60f + dx - 44f, 150f + dy - 26f), androidx.compose.ui.geometry.Size(88f, 52f), androidx.compose.ui.geometry.CornerRadius(7f)) + symbol(side, Offset(60f + dx, 150f + dy), 18f) + } + drawCircle(ChaosColours.Chute, 34f, Offset(60f, 150f)) + drawCircle(ChaosColours.channel[2], 20f, Offset(60f, 150f)); symbol(Chan.RIGHT, Offset(60f, 150f), 11f) + } + } + } + } + Column(verticalArrangement = Arrangement.spacedBy(6.dp)) { + Text("SEND EACH SIGNAL HOME", color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 24.sp) + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { KeyCap("◀▶▲▼"); Text("Send it to the screen", color = ArcadeColours.Ink, fontSize = 15.sp) } + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { KeyCap("OK"); Text("Bin the grey static", color = ArcadeColours.Ink, fontSize = 15.sp) } + Text("• Wrong screen? It gets static", color = ArcadeColours.Muted, fontSize = 14.sp) + Text("• Three jammed screens ends the run", color = ArcadeColours.Muted, fontSize = 14.sp) + } + } + Spacer(Modifier.height(10.dp)) + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp)) { + Row { Text("Your best ", color = ArcadeColours.Muted, fontSize = 14.sp); Text(if (best > 0) "%,d".format(best) else "Not played yet", color = ArcadeColours.Ink, fontSize = 14.sp, fontWeight = FontWeight.Bold) } + Row { Text("Best stage ", color = ArcadeColours.Muted, fontSize = 14.sp); Text(if (bestStage > 0) "$bestStage" else "—", color = ArcadeColours.Ink, fontSize = 14.sp, fontWeight = FontWeight.Bold) } + Text(difficulty, Modifier.background(ArcadeColours.Cyan, RoundedCornerShape(10.dp)).padding(horizontal = 8.dp), color = ArcadeColours.Night, fontSize = 12.sp, fontWeight = FontWeight.Bold) + Text("🔒 No Household record: Channel Chaos is new since profiles", color = ArcadeColours.Muted, fontSize = 13.sp) + } + Spacer(Modifier.height(8.dp)) + KeyFooter(listOf(Control("▲▼", "Choose"), Control("OK", "Select"), Control("Back", "Arcade home"))) + } + } +} + +// ---------- Play (frames 31 and 32) ---------- + +@Composable +private fun ChaosPlay(art: ChaosArt, logo: androidx.compose.ui.graphics.ImageBitmap, sim: ChaosSim, hud: ChaosHud, calm: Boolean, reduceFlashing: Boolean) { + val bonus = hud.bonusSecs > 0 + Box(Modifier.fillMaxSize().background(ArcadeColours.Night)) { + Column(Modifier.fillMaxSize().padding(start = 40.dp, end = 40.dp, top = 22.dp, bottom = 10.dp)) { + Row(Modifier.fillMaxWidth().weight(1f)) { + // Left: score, chain, stage (or the bonus round's seconds), jammed screens; Ollie's hint below. + Column(Modifier.width(180.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(2.dp)) { + HudLabel("SCORE") + Text("%,d".format(hud.score), color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 30.sp) + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) { + Text("×${hud.chain}", Modifier.background(ArcadeColours.Pink, RoundedCornerShape(12.dp)).padding(horizontal = 10.dp), color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 17.sp) + Text("chain", color = ArcadeColours.Muted, fontSize = 14.sp) + } + Spacer(Modifier.height(10.dp)) + if (bonus) { + HudLabel("BONUS ROUND") + Text("${hud.bonusSecs} s", color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 30.sp) + Text("left to play", color = ArcadeColours.Muted, fontSize = 14.sp) + } else { + HudLabel("STAGE") + Text("${hud.stage}", color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 30.sp) + Spacer(Modifier.height(8.dp)) + HudLabel("JAMMED") + Row(horizontalArrangement = Arrangement.spacedBy(5.dp)) { + for (i in 0 until 3) Box(Modifier.size(24.dp, 16.dp).background(if (i < hud.jammed) Color(0xFF3A1020) else Color(0xFF2A3558), RoundedCornerShape(4.dp)) + .border(1.dp, if (i < hud.jammed) ChaosColours.Red else ChaosColours.TvEdge, RoundedCornerShape(4.dp))) + } + Text("${hud.jammed} of 3 screens", color = ArcadeColours.Muted, fontSize = 14.sp) + } + Spacer(Modifier.weight(1f)) + // Ollie keeps the broadcast running (Blaze hosts the bonus round, happy-eyed). + val words = if (hud.phase == Phase.Reward) Interludes.BACK_ON_AIR else hintWords(hud.hint, hud.hintSide) + if (words != null) Text(words, 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) + Canvas(Modifier.size(64.dp)) { + val who = if (bonus) Speaker.Blaze else Speaker.Ollie + drawImage(art.faces[who.ordinal], IntOffset.Zero, art.faceSize, IntOffset.Zero, IntSize(size.width.toInt(), size.height.toInt())) + } + } + // The field: the four screens and the chute, in the frame's own units. + Canvas(Modifier.weight(1f).fillMaxHeight()) { + hud.frame // redraw every frame, without recomposing + val k = minOf(size.width / 1100f, size.height / 890f) + val ox = (size.width - 1100f * k) / 2; val oy = (size.height - 890f * k) / 2 + val t = sim.clock + translate(ox, oy) { + scale(k, k, Offset.Zero) { + translate(-410f, -40f) { + with(art) { + val tuned = sim.phase == Phase.Reward || sim.phase == Phase.Interlude + for (side in 0 until Chan.SCREENS) screen(sim, side, t, calm, tuned) + if (sim.phase == Phase.Reward) ident(logo, sim.phaseT, calm || reduceFlashing) else chute(sim, t, calm, reduceFlashing) + } + } + } + } + } + // Right: the power-up on now, and Drift when he drifts past with his muddled signal. + Column(Modifier.width(170.dp).fillMaxHeight(), horizontalAlignment = Alignment.End, verticalArrangement = Arrangement.spacedBy(4.dp)) { + HudLabel("POWER-UP") + val p = hud.power ?: if (hud.autoLeft > 0) ChaosPower.AutoTune else null + Canvas(Modifier.size(56.dp)) { + hud.frame + val now = sim.timedPower + with(art) { if (p != null) badge(p, center, size.minDimension * .3f) } + if (now != null) drawArc(ChaosColours.power.getValue(now), -90f, 360f * (sim.powerLeft / now.seconds).coerceIn(0f, 1f), false, + Offset(4f, 4f), androidx.compose.ui.geometry.Size(size.width - 8f, size.height - 8f), style = androidx.compose.ui.graphics.drawscope.Stroke(3.dp.toPx())) + } + if (p != null) { + Text(p.title, color = ArcadeColours.Ink, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, textAlign = TextAlign.End) + Text(if (p == ChaosPower.AutoTune) "${hud.autoLeft} to go" else "${hud.powerSecs} s left", color = ChaosColours.power.getValue(p), fontSize = 13.sp) + } else Text("None yet", color = ArcadeColours.Muted, fontSize = 13.sp) + if (hud.drift) { + Spacer(Modifier.height(18.dp)) + Canvas(Modifier.size(70.dp)) { drawImage(art.faces[Speaker.Drift.ordinal], IntOffset.Zero, art.faceSize, IntOffset.Zero, IntSize(size.width.toInt(), size.height.toInt())) } + Text("Drift's about…", color = ArcadeColours.Muted, fontSize = 13.sp) + } + } + } + Spacer(Modifier.height(6.dp)) + KeyFooter(if (bonus) listOf(Control("◀▶▲▼", "Send to that screen"), Control("Back", "Pause")) + else listOf(Control("◀▶▲▼", "Send to that screen"), Control("OK", "Bin static"), Control("Back", "Pause")), + note = if (bonus) "No static drops in the bonus round" else null) + } + } +} + +@Composable +private fun HudLabel(text: String) = Text(text, color = ArcadeColours.Muted, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp) + +// ---------- Between rounds ---------- + +/** One of the cast's interruptions: a face and a caption (only Ollie has a mouth), shown still, waiting for OK. */ +@Composable +private fun InterludeCard(art: ChaosArt, line: Interludes.Line, repaired: Int) { + Box(Modifier.fillMaxSize().background(ArcadeColours.Night.copy(alpha = .6f)), contentAlignment = Alignment.Center) { + Row(Modifier.background(ArcadeColours.PanelDeep, RoundedCornerShape(16.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(16.dp)).padding(22.dp), + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(18.dp)) { + Canvas(Modifier.size(110.dp)) { drawImage(art.faces[line.who.ordinal], IntOffset.Zero, art.faceSize, IntOffset.Zero, IntSize(size.width.toInt(), size.height.toInt())) } + Column(Modifier.widthIn(max = 420.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { + Text(line.who.name.uppercase(), color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp) + Text(line.text, Modifier.background(ArcadeColours.Ink, RoundedCornerShape(12.dp)).padding(horizontal = 14.dp, vertical = 10.dp), + color = ArcadeColours.Night, fontSize = 20.sp, fontWeight = FontWeight.SemiBold) + if (repaired >= 0) Text("${Chan.names[repaired]} is back on air.", color = ArcadeColours.Green, fontSize = 15.sp) + Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) { KeyCap("OK"); Text("Continue", color = ArcadeColours.Ink, fontSize = 15.sp) } + } + } + } +} + +// ---------- Result (frame 33) ---------- + +@Composable +private fun ChaosResult(art: ChaosArt, sim: ChaosSim, bestBefore: Int, onRetry: () -> Unit, onBack: () -> Unit) { + val first = remember { FocusRequester() } + LaunchedEffect(Unit) { runCatching { first.requestFocus() } } + BackHandler(onBack = onBack) + val newBest = sim.score > bestBefore && sim.score > 0 + 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(110.dp)) { drawImage(art.faces[Speaker.Ollie.ordinal], IntOffset.Zero, art.faceSize, IntOffset.Zero, IntSize(size.width.toInt(), size.height.toInt())) } + Column(Modifier.width(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("CHANNEL CHAOS · STAGE ${sim.stage} REACHED", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.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("SCORE", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 2.sp) + Text("%,d".format(sim.score), color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 54.sp) + Text(if (bestBefore > 0) "Previous best ${"%,d".format(bestBefore)}" else "Your first Channel Chaos score", color = ArcadeColours.Ink, fontSize = 14.sp) + Text("Best chain ×${sim.bestChain} · ${sim.sent} signals sent · ${sim.binned} static binned", color = ArcadeColours.Muted, fontSize = 13.sp) + Spacer(Modifier.height(6.dp)) + Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) { + ArcadeButton("Play Again", Modifier.width(160.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = onRetry) + ArcadeButton("Back to Arcade", Modifier.width(200.dp), icon = "←", height = 34.dp, onClick = onBack) + } + } + Canvas(Modifier.size(110.dp)) { drawImage(art.faces[Speaker.Blaze.ordinal], IntOffset.Zero, art.faceSize, IntOffset.Zero, IntSize(size.width.toInt(), size.height.toInt())) } + } + 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)) + } +} diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChaosArt.kt b/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChaosArt.kt new file mode 100644 index 00000000..8f94c890 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChaosArt.kt @@ -0,0 +1,268 @@ +package tv.orbit.classic.arcade.chaos + +import androidx.compose.ui.geometry.CornerRadius +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.Path +import androidx.compose.ui.graphics.PathEffect +import androidx.compose.ui.graphics.StrokeCap +import androidx.compose.ui.graphics.drawscope.CanvasDrawScope +import androidx.compose.ui.graphics.drawscope.DrawScope +import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.graphics.drawscope.scale +import androidx.compose.ui.graphics.drawscope.translate +import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.text.TextMeasurer +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.drawText +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.unit.LayoutDirection +import androidx.compose.ui.unit.sp +import tv.orbit.classic.OrbCharacter +import tv.orbit.classic.OrbDir +import tv.orbit.classic.arcade.hexPath +import tv.orbit.classic.drawOrbBee +import tv.orbit.classic.drawOrbChaser +import tv.orbit.classic.drawOrbMascot +import tv.orbit.classic.starPath +import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.sin + +/** Channel identity by colour AND symbol (Stage B): Orbit 1 is a cyan star, so it can't be mixed up with Tots' amber sun. */ +internal object ChaosColours { + val channel = arrayOf(Color(0xFF35D6F2), Color(0xFFFF2EA6), Color(0xFF9BE564), Color(0xFFFFB52E)) + val TvBody = Color(0xFF2A3558) + val TvEdge = Color(0xFF7FB2FF) + val Plate = Color(0xFF0C1F4A) + val Line = Color(0xFF3D63B8) + val Chute = Color(0xFF1E3E7A) + val Static = Color(0xFFB9C2D6) + val Red = Color(0xFFFF6B6B) + val Navy = Color(0xFF14213D) + val Ink = Color(0xFFF4F6FB) + val power = mapOf(ChaosPower.Freeze to Color(0xFF8FE3FF), ChaosPower.AutoTune to Color(0xFF2BB3A8), ChaosPower.Sweep to Color(0xFF9BE564), + ChaosPower.DoublePoints to Color(0xFFE85DFF), ChaosPower.Reception to Color(0xFF4F8BFF)) + fun mixed(c: Color) = c.copy(alpha = .42f) +} + +/** The cast, drawn once into small bitmaps from the cast library (it builds little lists as it draws). Only Ollie has a mouth. */ +internal fun castFace(who: Speaker, px: Int, density: Density, happy: Boolean = false): ImageBitmap { + val image = ImageBitmap(px, px) + CanvasDrawScope().draw(density, LayoutDirection.Ltr, androidx.compose.ui.graphics.Canvas(image), Size(px.toFloat(), px.toFloat())) { + val c = Offset(px / 2f, px / 2f); val r = px * .32f + when (who) { + Speaker.Ollie -> drawOrbMascot(c, r, OrbDir.Right) + Speaker.Blaze -> drawOrbChaser(c, r * 1.1f, OrbCharacter.Blaze, OrbDir.Up, false, false, false, 0f, lookAt = if (happy) Offset(0f, -1f) else Offset(.4f, -.6f)) + Speaker.Drift -> drawOrbChaser(c, r * 1.1f, OrbCharacter.Drift, OrbDir.Left, false, false, false, .3f, lookAt = Offset(-.6f, .4f)) + Speaker.Bumble -> drawOrbBee(c, r) + } + } + return image +} + +/** + * The play field's drawing, in the Stage B frame's own units (the 1920×1080 frame, cropped to the screens and chute: + * x 410-1510, y 40-930). Paths, noise and names are made once; a frame draws without allocating. + */ +internal class ChaosArt(density: Density, measurer: TextMeasurer) { + val faces = Speaker.entries.map { castFace(it, 128, density) }.toTypedArray() + val faceSize = IntSize(128, 128) + + private val names: Array = Chan.names.map { measurer.measure(it, TextStyle(fontSize = 28.sp, fontWeight = FontWeight.SemiBold), density = density) }.toTypedArray() + private val nameScale = 28f / names[0].size.height.coerceAtLeast(1) * 1.2f + private val jammedWord = measurer.measure("JAMMED", TextStyle(fontSize = 28.sp, fontWeight = FontWeight.Bold), density = density) + private val five = measurer.measure("×5", TextStyle(fontSize = 28.sp, fontWeight = FontWeight.SemiBold), density = density) + private val arrows = arrayOf("▲", "◀", "▶", "▼").map { measurer.measure(it, TextStyle(fontSize = 20.sp, fontWeight = FontWeight.Bold), density = density) }.toTypedArray() + + // Symbols at unit size (about 2 across), scaled where they're drawn. + private val star = starPath(Offset.Zero, 1f, .45f, 0f) + private val bolt = Path().apply { moveTo(.25f, -1f); lineTo(-.55f, .12f); lineTo(-.02f, .12f); lineTo(-.3f, 1f); lineTo(.58f, -.18f); lineTo(.06f, -.18f); close() } + private val leaf = Path().apply { moveTo(-.8f, .8f); cubicTo(-.9f, -.3f, -.1f, -.95f, .9f, -.9f); cubicTo(.95f, .1f, .3f, .9f, -.8f, .8f); close() } + private val hex = hexPath(Offset.Zero, 1f) + private val spiral = Path().apply { + for (i in 0 until 36) { + val a = (200 + i * 9) * PI / 180; val r = 138 - i * 2.2 + val x = (cos(a) * r).toFloat(); val y = (sin(a) * r).toFloat() + if (i == 0) moveTo(x, y) else lineTo(x, y) + } + } + private val dashes = Stroke(3f, pathEffect = PathEffect.dashPathEffect(floatArrayOf(4f, 10f))) + private val thin = Stroke(2f) + private val ring = Stroke(5f, cap = StrokeCap.Round) + private val rays = Stroke(.16f, cap = StrokeCap.Round) + private val leafVein = Stroke(.12f, cap = StrokeCap.Round) + /** TV static: 140 specks per screen, in unit coordinates, picked once. */ + private val noise = FloatArray(140 * 3).also { a -> val r = java.util.Random(7); for (i in 0 until 140) { a[i * 3] = r.nextFloat(); a[i * 3 + 1] = r.nextFloat(); a[i * 3 + 2] = r.nextFloat() } } + private val shades = arrayOf(Color(0xFFFFFFFF), Color(0xFFC9D2E6), Color(0xFF8D99B6), Color(0xFF5E6A85)) + + /** Where the screens sit in the frame: the centre x and top of each TV (Stage B frame 31). */ + val tvX = floatArrayOf(960f, 560f, 1360f, 960f) + val tvTop = floatArrayOf(80f, 395f, 395f, 702f) + val chuteX = 960f + val chuteY = 500f + + // ---------- symbols, signals ---------- + + fun DrawScope.symbol(side: Int, c: Offset, s: Float, colour: Color = Color.White) { + translate(c.x, c.y) { + scale(s, s, Offset.Zero) { + when (side) { + Chan.UP -> drawPath(star, colour) + Chan.LEFT -> drawPath(bolt, colour) + Chan.RIGHT -> { drawPath(leaf, colour); drawLine(Color(0x8C1C6B46), Offset(-.8f, .8f), Offset(.45f, -.45f), .12f, StrokeCap.Round) } + else -> { + for (k in 0 until 8) { val a = k * PI.toFloat() / 4; drawLine(colour, Offset(cos(a) * .62f, sin(a) * .62f), Offset(cos(a) * .98f, sin(a) * .98f), .16f, StrokeCap.Round) } + drawCircle(colour, .46f, Offset.Zero) + } + } + } + } + } + + /** A signal: its channel's colour and symbol; static is a grey fuzz with eyes; a power-up rides in its hexagon. */ + fun DrawScope.signal(sim: ChaosSim, i: Int, c: Offset, r: Float, alpha: Float, bonus: Boolean) { + when (val k = sim.kind[i]) { + Chan.STATIC -> staticSprite(c, r, alpha) + Chan.POWER -> { val p = sim.power[i]; if (p != null) badge(p, c, r * .9f, alpha) } + Chan.MIXED -> { + val a = ChaosColours.channel[sim.mixA[i]]; val b = ChaosColours.channel[sim.mixB[i]] + drawCircle(a, r * 1.25f, c, alpha = .16f * alpha) + drawArc(a, 90f, 180f, true, Offset(c.x - r, c.y - r), Size(r * 2, r * 2), alpha = alpha) + drawArc(b, 270f, 180f, true, Offset(c.x - r, c.y - r), Size(r * 2, r * 2), alpha = alpha) + symbol(sim.mixA[i], Offset(c.x - r * .42f, c.y), r * .32f) + symbol(sim.mixB[i], Offset(c.x + r * .42f, c.y), r * .32f) + drawCircle(Color.White, r * 1.16f, c, alpha = .8f * alpha, style = dashes) + } + else -> { + val col = ChaosColours.channel[k] + drawCircle(col, r * 1.25f, c, alpha = .16f * alpha) + drawCircle(col, r, c, alpha = alpha) + drawCircle(Color.White, r * .3f, Offset(c.x - r * .3f, c.y - r * .35f), alpha = .25f * alpha) + symbol(k, Offset(c.x, c.y + r * .04f), r * .56f) + if (bonus) drawCircle(Color.White, r * 1.16f, c, alpha = .8f * alpha, style = dashes) + } + } + } + + fun DrawScope.staticSprite(c: Offset, r: Float, alpha: Float = 1f) { + drawCircle(ChaosColours.Static, r, c, alpha = alpha) + for (k in 0 until 8) { val a = k * .785f; drawCircle(Color(0xFF8D99B6), r * .22f, Offset(c.x + cos(a) * r * .9f, c.y + sin(a) * r * .9f), alpha = alpha) } + drawCircle(Color.White, r * .22f, Offset(c.x - r * .3f, c.y - r * .1f), alpha = alpha); drawCircle(Color.White, r * .22f, Offset(c.x + r * .3f, c.y - r * .1f), alpha = alpha) + drawCircle(ChaosColours.Navy, r * .11f, Offset(c.x - r * .28f, c.y - r * .08f), alpha = alpha); drawCircle(ChaosColours.Navy, r * .11f, Offset(c.x + r * .32f, c.y - r * .08f), alpha = alpha) + } + + /** A power-up badge in the hexagon family: its colour and its family's symbol. */ + fun DrawScope.badge(p: ChaosPower, c: Offset, r: Float, alpha: Float = 1f) { + val col = ChaosColours.power.getValue(p) + translate(c.x, c.y) { + scale(r, r, Offset.Zero) { + drawPath(hex, col, alpha = alpha) + drawPath(hex, Color.White, alpha = .5f * alpha, style = Stroke(.08f)) + val ink = ChaosColours.Navy + when (p) { + ChaosPower.Freeze -> { drawLine(ink, Offset(-.35f, -.5f), Offset(.35f, .5f), .12f); drawLine(ink, Offset(.35f, -.5f), Offset(-.35f, .5f), .12f); drawLine(ink, Offset(-.4f, -.5f), Offset(.4f, -.5f), .12f); drawLine(ink, Offset(-.4f, .5f), Offset(.4f, .5f), .12f) } + ChaosPower.AutoTune -> { drawArc(ink, 160f, 220f, false, Offset(-.45f, -.45f), Size(.9f, .9f), style = Stroke(.12f)); drawLine(ink, Offset.Zero, Offset(.25f, -.25f), .12f, StrokeCap.Round) } + ChaosPower.Sweep -> for (k in 0 until 8) { val a = k * .785f; drawLine(ink, Offset(cos(a) * .2f, sin(a) * .2f), Offset(cos(a) * .55f, sin(a) * .55f), .1f, StrokeCap.Round) } + ChaosPower.DoublePoints -> { translate(-.18f, -.1f) { scale(.32f, .32f, Offset.Zero) { drawPath(star, Color.White) } }; translate(.2f, .14f) { scale(.26f, .26f, Offset.Zero) { drawPath(star, Color.White) } } } + ChaosPower.Reception -> drawPath(hex, Color.White, alpha = .9f, style = Stroke(.1f)) + } + } + } + } + + // ---------- the screens ---------- + + /** One channel's screen and its name plate with the interference meter. Jammed: thick static and JAMMED. */ + fun DrawScope.screen(sim: ChaosSim, side: Int, time: Float, calm: Boolean, tuned: Boolean) { + val cx = tvX[side]; val top = tvTop[side]; val x = cx - 150f + val col = ChaosColours.channel[side] + val bonus = sim.bonus > 0f + if (side != Chan.DOWN) { + drawLine(Color(0xFFAEBBD2), Offset(cx - 16f, top), Offset(cx - 34f, top - 22f), 4f, StrokeCap.Round) + drawLine(Color(0xFFAEBBD2), Offset(cx + 16f, top), Offset(cx + 34f, top - 22f), 4f, StrokeCap.Round) + } + if (bonus || tuned) drawRoundRect(col, Offset(x - 14f, top - 14f), Size(328f, 178f), CornerRadius(30f), alpha = .22f) + drawRoundRect(ChaosColours.TvBody, Offset(x, top), Size(300f, 150f), CornerRadius(20f)) + drawRoundRect(ChaosColours.TvEdge, Offset(x, top), Size(300f, 150f), CornerRadius(20f), style = thin) + drawRoundRect(if (sim.jammed[side] && !tuned) Color(0xFF2B2F3D) else ChaosColours.mixed(col), Offset(x + 10f, top + 10f), Size(280f, 130f), CornerRadius(12f)) + if (!sim.jammed[side] || tuned) { + drawCircle(col, 52f, Offset(cx, top + 75f), alpha = .5f) + symbol(side, Offset(cx, top + 75f), 40f) + } + // Interference: specks across the screen, more as the meter rises; they shimmer (still under Reduce motion). + val level = if (tuned) 0f else if (sim.jammed[side]) 1f else sim.meter[side] + val n = (level * 140).toInt() + val shift = if (calm) 0f else (time * 9f) % 1f + for (i in 0 until n) { + val ux = (noise[i * 3] + shift * (i % 3) * .37f) % 1f + drawRect(shades[i % 4], Offset(x + 12f + ux * 268f, top + 12f + noise[i * 3 + 1] * 120f), Size(7f, 4.2f), alpha = .55f + noise[i * 3 + 2] * .4f) + } + for (k in 0 until 18) drawRect(Color.White, Offset(x + 10f, top + 10f + k * 7f), Size(280f, 2f), alpha = .05f) + if (sim.jammed[side] && !tuned) translate(cx - jammedWord.size.width * nameScale / 2, top + 50f) { scale(nameScale, nameScale, Offset.Zero) { drawText(jammedWord, ChaosColours.Red) } } + // The name plate. + val py = top + 158f + drawRoundRect(ChaosColours.Plate, Offset(x, py), Size(300f, 56f), CornerRadius(14f)) + drawRoundRect(ChaosColours.Line, Offset(x, py), Size(300f, 56f), CornerRadius(14f), style = thin) + translate(x + 22f, py + 10f) { scale(nameScale, nameScale, Offset.Zero) { drawText(names[side], ChaosColours.Ink) } } + if (bonus) translate(x + 300f - 22f - five.size.width * nameScale, py + 10f) { scale(nameScale, nameScale, Offset.Zero) { drawText(five, col) } } + else { + val mx = x + 168f; val mw = 110f + drawRoundRect(Color(0xFF081A3C), Offset(mx, py + 20f), Size(mw, 16f), CornerRadius(8f)) + drawRoundRect(Color(0xFF2A4A80), Offset(mx, py + 20f), Size(mw, 16f), CornerRadius(8f), style = Stroke(1.5f)) + val m = if (sim.jammed[side]) 1f else sim.meter[side] + if (m > 0f) drawRoundRect(if (m >= .6f) ChaosColours.Red else Color(0xFF9FAAC4), Offset(mx + 2f, py + 22f), Size((mw - 4f) * m, 12f), CornerRadius(6f)) + } + } + + // ---------- the chute ---------- + + fun DrawScope.chute(sim: ChaosSim, time: Float, calm: Boolean, reduceFlashing: Boolean) { + val c = Offset(chuteX, chuteY) + drawCircle(ChaosColours.Chute, 138f, c, alpha = .6f); drawCircle(ChaosColours.TvEdge, 138f, c, alpha = .25f, style = Stroke(3f)) + drawCircle(ChaosColours.Chute, 108f, c, alpha = .66f); drawCircle(ChaosColours.TvEdge, 108f, c, alpha = .4f, style = Stroke(3f)) + drawCircle(ChaosColours.Chute, 78f, c, alpha = .74f); drawCircle(ChaosColours.TvEdge, 78f, c, alpha = .55f, style = Stroke(3f)) + translate(c.x, c.y) { drawPath(spiral, if (sim.bonus > 0f) Color.White else ChaosColours.channel[0], alpha = .35f, style = dashes) } + val bonus = sim.bonus > 0f + // The next two, spiralling in. + signal(sim, 2, Offset(c.x - 150f, c.y - 150f), 20f, .6f, bonus) + signal(sim, 1, Offset(c.x - 98f, c.y - 82f), 30f, 1f, bonus) + drawCircle(Color(0xFF081A3C), 62f, c); drawCircle(Color.White, 62f, c, alpha = .4f, style = Stroke(3f)) + // The time left for the middle signal, as a ring round it (none on Gentle's untimed stages). + if (sim.timed && sim.phase == Phase.Playing) { + val f = (sim.left / sim.leftTotal).coerceIn(0f, 1f) + drawArc(if (f < .3f) ChaosColours.Red else Color.White, -90f, 360f * f, false, Offset(c.x - 70f, c.y - 70f), Size(140f, 140f), alpha = .8f, style = ring) + } + if (sim.phase == Phase.Playing) signal(sim, 0, c, 44f, 1f, bonus) + // Where the last one went: a soft line to that screen, green or red. A steady line with Reduce flashing on. + if (sim.lastSide >= 0 && sim.lastT < .35f) { + val a = if (reduceFlashing || calm) .5f else 1f - sim.lastT / .35f + val to = Offset(tvX[sim.lastSide], tvTop[sim.lastSide] + 75f) + drawLine(if (sim.lastGood) Color(0xFF6EDCAA) else ChaosColours.Red, c, to, 6f, StrokeCap.Round, alpha = a * .6f) + } + // The arrow chips between the chute and each screen. + chip(0, Offset(960f, 330f)); chip(3, Offset(960f, 672f)); chip(1, Offset(764f, 500f)); chip(2, Offset(1156f, 500f)) + } + + private fun DrawScope.chip(i: Int, c: Offset) { + drawRoundRect(Color(0xFF13306B), Offset(c.x - 24f, c.y - 21f), Size(48f, 42f), CornerRadius(8f)) + drawRoundRect(ChaosColours.TvEdge, Offset(c.x - 24f, c.y - 21f), Size(48f, 42f), CornerRadius(8f), style = thin) + val t = arrows[i]; val k = 1.3f + translate(c.x - t.size.width * k / 2, c.y - t.size.height * k / 2) { scale(k, k, Offset.Zero) { drawText(t, ChaosColours.Ink) } } + } + + /** The reward: every screen on its own channel, and the little Orbit ident in the chute. */ + fun DrawScope.ident(logo: ImageBitmap, t: Float, calm: Boolean) { + val c = Offset(chuteX, chuteY) + val grow = if (calm) 1f else (t / .6f).coerceIn(0f, 1f) + drawCircle(Color(0xFF081A3C), 140f, c) + drawCircle(ChaosColours.channel[0], 140f, c, alpha = .35f, style = Stroke(4f)) + val w = 220f * (.6f + .4f * grow); val h = w * logo.height / logo.width.coerceAtLeast(1) + drawImage(logo, IntOffset.Zero, IntSize(logo.width, logo.height), IntOffset((c.x - w / 2).toInt(), (c.y - h / 2).toInt()), IntSize(w.toInt(), h.toInt()), alpha = .4f + .6f * grow) + } +} diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChaosSim.kt b/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChaosSim.kt new file mode 100644 index 00000000..404e33d2 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/arcade/chaos/ChaosSim.kt @@ -0,0 +1,433 @@ +package tv.orbit.classic.arcade.chaos + +import tv.orbit.classic.arcade.Difficulty +import tv.orbit.classic.arcade.raiders.SeededRandom + +/** + * Channel Chaos (Arcade prototype, 8 November 2026), from the approved Stage B frames 30-33 and Paul's notes: signals drop + * into the tuning chute and the remote sends each to its channel's screen. ▲ Orbit 1 (cyan star), ◀ Riot (pink bolt), + * ▶ Terra (green leaf), ▼ Tots (amber sun). OK bins grey static. A wrong screen, static sent to a screen, or a signal left + * too long puts interference on a screen; a full meter jams it, and three jammed screens end the run. + * + * "Increasingly chaotic without becoming frustrating" (Paul): one new thing a stage. Stage 1 plain signals, slowly; stage 2 + * static; stage 3 power-ups; from stage 4 Drift's muddled deliveries. Every third stage ends in Blaze's bonus round. On + * Gentle the first two stages have no timer at all. + * + * Between rounds: the four screens tune in, a little Orbit ident, "And we're back on air!" ([Phase.Reward]), then one of the + * cast's interruptions ([Phase.Interlude]), which waits for OK. Pure rules, seeded, fixed 60 Hz step, no allocation in play. + */ +internal object Chan { + const val UP = 0 // Orbit 1 + const val LEFT = 1 // Riot + const val RIGHT = 2 // Terra + const val DOWN = 3 // Tots + const val SCREENS = 4 + const val STATIC = 4 + /** A power-up badge riding the chute: any direction or OK collects it. */ + const val POWER = 5 + /** Drift's muddled delivery: two channels at once, and either of their screens takes it (for double points). */ + const val MIXED = 6 + + val names = arrayOf("Orbit 1", "Riot", "Terra", "Tots") +} + +/** Channel Chaos's power-ups (Stage B power-up family sheet). One timed at a time; a new one replaces it. */ +internal enum class ChaosPower(val title: String, val line: String, val seconds: Float, val weight: Int) { + Freeze("Channel Freeze", "Signals stop falling", 8f, 20), + AutoTune("Auto Tune", "Next 5 signals send themselves", 0f, 18), + Sweep("Signal Sweep", "Clears static from the chute and screens", 0f, 22), + DoublePoints("Double Points", "Every match scores twice", 12f, 22), + Reception("Perfect Reception", "Wrong sends add no static", 10f, 18); + + val timed get() = seconds > 0f +} + +/** How hard the chute pushes (Arcade Settings › Difficulty; Kids start on Gentle). */ +internal class ChaosTuning(val time: Float, val static: Float, val hurt: Float, val untimedStages: Int) { + companion object { + /** Gentle: "give players time to think": no timer for the first two stages, then half again as long. */ + val Gentle = ChaosTuning(1.6f, .6f, .6f, 2) + val Normal = ChaosTuning(1f, 1f, 1f, 0) + val Tricky = ChaosTuning(.78f, 1.3f, 1.2f, 0) + fun of(d: Difficulty) = when (d) { Difficulty.Gentle -> Gentle; Difficulty.Normal -> Normal; Difficulty.Tricky -> Tricky } + } +} + +/** What happened this tick, for sounds; read and cleared by the screen. */ +internal object ChaosEvents { + const val MATCH = 1 + const val WRONG = 2 + const val BIN = 4 + const val MISSED = 8 + const val JAMMED = 16 + const val STAGE = 32 + const val BONUS = 64 + const val POWER = 128 + const val OVER = 256 + const val REPAIRED = 512 +} + +/** Ollie's hints during play (Blaze's in the bonus round), as numbers; the screen has the words. */ +internal object Hint { + const val NONE = 0 + const val HELLO = 1 + const val STATIC = 2 + const val NEARLY = 3 // a screen is nearly jammed: hintSide says which + const val JAMMED = 4 + const val BONUS = 6 + const val MIXED = 7 + const val POWER = 8 +} + +/** Who's speaking in an interruption between rounds. Only Ollie has a mouth; the others speak in captions. */ +internal enum class Speaker { Ollie, Blaze, Drift, Bumble } + +/** The interruptions between rounds. Paul's two are as he wrote them; the rest are in the same spirit. */ +internal object Interludes { + class Line(val who: Speaker, val text: String) + val FASTER = Line(Speaker.Blaze, "FASTER! WE'RE LOSING VIEWERS!") + val SUPPOSED = Line(Speaker.Drift, "Oh. Was that supposed to go somewhere?") + val ALL = arrayOf( + FASTER, + SUPPOSED, + Line(Speaker.Blaze, "Bigger! Louder! MORE CHANNELS!"), + Line(Speaker.Drift, "I found this signal under a cloud. Is it yours?"), + Line(Speaker.Blaze, "Nobody blink. The ratings are watching."), + Line(Speaker.Drift, "I sent one to the moon. It seemed happy there."), + Line(Speaker.Ollie, "Steady hands. The viewers are with us."), + ) + /** Before Blaze's bonus round, always his. */ + val BONUS = Line(Speaker.Blaze, "Bonus round! No static, just points. Go go go!") + /** When Bumble rushes in to repair a jammed screen. */ + val REPAIR = Line(Speaker.Bumble, "Hold still, transmitter! Bumble's on it!") + /** The level-complete reward's last word. */ + const val BACK_ON_AIR = "And we're back on air!" +} + +/** Where a run stands. */ +internal enum class Phase { Playing, Reward, Interlude, Over } + +internal class ChaosSim(difficulty: Difficulty = Difficulty.Normal, var seed: Int = 1) { + var difficulty = difficulty; private set + var tuning = ChaosTuning.of(difficulty); private set + private val rng = SeededRandom(seed) + /** Reduce motion: the reward holds still (the screens show their channels at once) and nothing slides in. */ + var calm = false + + // ---------- the chute: the middle signal and the next two ---------- + val kind = IntArray(3) + /** A MIXED signal's two channels. */ + val mixA = IntArray(3) + val mixB = IntArray(3) + val power = arrayOfNulls(3) + /** Seconds before the middle signal falls out unsent ([timed] false: no timer, Gentle's first stages). */ + var left = 0f; private set + var leftTotal = 1f; private set + val timed get() = stage > tuning.untimedStages || bonus > 0f + + // ---------- the screens ---------- + val meter = FloatArray(Chan.SCREENS) + val jammed = BooleanArray(Chan.SCREENS) + var lastSide = -1; private set + var lastGood = false; private set + var lastT = 9f; private set + + // ---------- the run ---------- + var phase = Phase.Playing; private set + var phaseT = 0f; private set + var score = 0; private set + var streak = 0; private set + val chain get() = minOf(6, 1 + streak / 4) + var bestChain = 1; private set + var stage = 1; private set + var stageSent = 0; private set + var sent = 0; private set + var binned = 0; private set + val over get() = phase == Phase.Over + /** Blaze's bonus round: seconds left (0 when it isn't on). */ + var bonus = 0f; private set + private var bonusNext = false + var timedPower: ChaosPower? = null; private set + var powerLeft = 0f; private set + var autoLeft = 0; private set + private var autoIn = 0f + /** Drift drifting past (seconds he's still about): from stage 4 his deliveries come muddled. */ + var drift = 0f; private set + private var driftIn = 8f + var hint = Hint.HELLO; private set + var hintSide = 0; private set + var hintT = 4f; private set + private var seenStatic = false + private var seenMixed = false + private var seenPower = false + /** The interruption showing between rounds. */ + var interlude: Interludes.Line = Interludes.FASTER; private set + /** The screen Bumble repaired at the end of this round, or -1. */ + var repaired = -1; private set + private var lineAt = 0 + var events = 0 + var clock = 0f; private set + var ticks = 0L; private set + + init { newRun(difficulty, seed) } + + fun newRun(difficulty: Difficulty = this.difficulty, seed: Int = this.seed) { + this.difficulty = difficulty; tuning = ChaosTuning.of(difficulty); this.seed = seed + rng.reseed(seed) + meter.fill(0f); jammed.fill(false) + phase = Phase.Playing; phaseT = 0f + score = 0; streak = 0; bestChain = 1; stage = 1; stageSent = 0; sent = 0; binned = 0 + bonus = 0f; bonusNext = false; timedPower = null; powerLeft = 0f; autoLeft = 0; autoIn = 0f; drift = 0f; driftIn = 8f + seenStatic = false; seenMixed = false; seenPower = false; lastSide = -1; lastT = 9f; clock = 0f; ticks = 0 + repaired = -1; lineAt = rng.nextInt(Interludes.ALL.size) + say(Hint.HELLO, 0) + for (i in 0 until 3) fill(i) + startCurrent() + } + + // ---------- making signals ---------- + + /** Seconds a signal waits in the middle: 3.4 s at stage 1, 12% quicker each stage, never under 0.75 s (× difficulty). */ + fun signalTime(): Float = maxOf(.75f, 3.4f * Math.pow(.88, (stage - 1).toDouble()).toFloat()) * tuning.time + + /** Static from stage 2 (one new thing at a time): 8% then more each stage, at most 35%; none in the bonus round. */ + fun staticChance(): Float = if (bonus > 0f || stage < 2) 0f else minOf(.35f, .03f + stage * .025f) * tuning.static + + /** Power-ups from stage 3. */ + fun powerChance(): Float = if (bonus > 0f || stage < 3) 0f else .05f + + /** Drift's muddled deliveries from stage 4, while he's drifting past. */ + fun mixedChance(): Float = if (bonus > 0f || stage < 4 || drift <= 0f) 0f else .3f + + private fun liveChannel(): Int { + var n = 0 + for (s in 0 until Chan.SCREENS) if (!jammed[s]) n++ + if (n == 0) return 0 + var pick = rng.nextInt(n) + for (s in 0 until Chan.SCREENS) if (!jammed[s]) { if (pick == 0) return s; pick-- } + return 0 + } + + private fun fill(i: Int) { + power[i] = null + val r = rng.nextFloat() + val st = staticChance(); val pw = powerChance(); val mx = mixedChance() + when { + r < st -> kind[i] = Chan.STATIC + r < st + pw -> { kind[i] = Chan.POWER; power[i] = pickPower() } + r < st + pw + mx && !queueHasMixed() -> { + val a = liveChannel(); var b = liveChannel() + if (b == a) b = (a + 1 + rng.nextInt(Chan.SCREENS - 1)) % Chan.SCREENS + if (jammed[b]) { kind[i] = a; return } + kind[i] = Chan.MIXED; mixA[i] = a; mixB[i] = b + } + else -> kind[i] = liveChannel() + } + } + + private fun queueHasMixed(): Boolean { for (k in kind) if (k == Chan.MIXED) return true; return false } + + private fun pickPower(): ChaosPower { + var total = 0 + for (p in POWERS) total += p.weight + var pick = rng.nextInt(total) + for (p in POWERS) { if (pick < p.weight) return p; pick -= p.weight } + return ChaosPower.Sweep + } + + /** Counts each signal arriving in the middle (the screen's little drop-in, and the tests' player). */ + var arrivals = 0L; private set + + private fun startCurrent() { + arrivals++ + leftTotal = signalTime(); left = leftTotal + when (kind[0]) { + Chan.STATIC -> if (!seenStatic) { seenStatic = true; say(Hint.STATIC, 0) } + Chan.MIXED -> if (!seenMixed) { seenMixed = true; say(Hint.MIXED, 0) } + Chan.POWER -> if (!seenPower) { seenPower = true; say(Hint.POWER, 0) } + } + } + + /** The middle signal is done with: the queue moves up and a new one joins at the back. */ + private fun advance() { + for (i in 0 until 2) { kind[i] = kind[i + 1]; mixA[i] = mixA[i + 1]; mixB[i] = mixB[i + 1]; power[i] = power[i + 1] } + fill(2) + startCurrent() + } + + /** Whether the middle signal belongs on [side]. */ + fun accepts(side: Int): Boolean = when (kind[0]) { + Chan.MIXED -> side == mixA[0] || side == mixB[0] + Chan.STATIC, Chan.POWER -> false + else -> kind[0] == side + } + + /** The screen the middle signal belongs on (for the bot and Auto Tune), or -1 for static and power-ups. */ + fun home(): Int = when (kind[0]) { Chan.MIXED -> mixA[0]; Chan.STATIC, Chan.POWER -> -1; else -> kind[0] } + + // ---------- the remote ---------- + + /** ▲ ◀ ▶ ▼: send the middle signal to that screen. */ + fun send(side: Int) { + if (phase != Phase.Playing) return + when (kind[0]) { + Chan.POWER -> { collect(power[0]!!); advance(); return } + Chan.STATIC -> { hurt(side, .3f); streak = 0; mark(side, false); events = events or ChaosEvents.WRONG } + else -> if (accepts(side)) match(side) else { + hurt(side, .3f) + streak = 0; mark(side, false); events = events or ChaosEvents.WRONG + } + } + sent++ + if (phase == Phase.Playing) advance() + } + + /** OK: bin the static (or take a power-up). On a channel's signal, it's thrown away, which its screen notices. */ + fun ok() { + when (phase) { + Phase.Reward -> { skipReward(); return } + Phase.Interlude -> { nextRound(); return } + Phase.Over -> return + Phase.Playing -> {} + } + when (kind[0]) { + Chan.POWER -> collect(power[0]!!) + Chan.STATIC -> { binned++; streak++; bestChain = maxOf(bestChain, chain); score += 5 * chain; events = events or ChaosEvents.BIN } + else -> { hurt(home(), .15f); streak = 0; events = events or ChaosEvents.WRONG } + } + advance() + } + + private fun match(side: Int) { + streak++ + bestChain = maxOf(bestChain, chain) + val mult = (if (bonus > 0f) 5 else 1) * (if (timedPower == ChaosPower.DoublePoints) 2 else 1) * (if (kind[0] == Chan.MIXED) 2 else 1) + score += 10 * chain * stage * mult + meter[side] = maxOf(0f, meter[side] - .12f) + mark(side, true) + events = events or ChaosEvents.MATCH + stageSent++ + if (bonus <= 0f && stageSent >= STAGE_SIGNALS) endRound() + } + + private fun mark(side: Int, good: Boolean) { lastSide = side; lastGood = good; lastT = 0f } + + /** Interference on a screen: none in the bonus round or under Perfect Reception. Full jams it; three jammed ends the run. */ + private fun hurt(side: Int, amount: Float) { + if (bonus > 0f || timedPower == ChaosPower.Reception || side < 0 || jammed[side]) return + val before = meter[side] + meter[side] = minOf(1f, meter[side] + amount * tuning.hurt) + if (before < .7f && meter[side] >= .7f && meter[side] < 1f) say(Hint.NEARLY, side) + if (meter[side] >= 1f) { + jammed[side] = true + events = events or ChaosEvents.JAMMED + say(Hint.JAMMED, side) + if (jammedCount >= 3) { phase = Phase.Over; events = events or ChaosEvents.OVER; return } + // Its signals stop coming: any already in the chute for it go elsewhere. + for (i in 0 until 3) { + if (kind[i] == side) kind[i] = liveChannel() + if (kind[i] == Chan.MIXED && (mixA[i] == side || mixB[i] == side)) kind[i] = liveChannel() + } + } + } + + val jammedCount: Int get() { var n = 0; for (j in jammed) if (j) n++; return n } + + // ---------- between rounds ---------- + + /** A stage (or the bonus round) is done: the reward, then an interruption, then the next round. */ + private fun endRound() { + val afterBonus = bonus > 0f + bonus = 0f; stageSent = 0; timedPower = null; powerLeft = 0f; autoLeft = 0 + // After the bonus round, Bumble rushes in to repair a jammed screen, if there is one. + repaired = -1 + if (afterBonus) for (s in 0 until Chan.SCREENS) if (jammed[s]) { jammed[s] = false; meter[s] = .4f; repaired = s; events = events or ChaosEvents.REPAIRED; break } + // Every third stage is followed by Blaze's bonus round. + bonusNext = !afterBonus && stage % 3 == 0 + if (!afterBonus && !bonusNext) stage++ + if (afterBonus) stage++ + interlude = when { + repaired >= 0 -> Interludes.REPAIR + bonusNext -> Interludes.BONUS + else -> Interludes.ALL[lineAt++ % Interludes.ALL.size] + } + phase = Phase.Reward; phaseT = 0f + events = events or ChaosEvents.STAGE + } + + /** OK during the reward: straight to the interruption. */ + private fun skipReward() { phase = Phase.Interlude; phaseT = 0f } + + /** OK on the interruption: the next round starts. */ + private fun nextRound() { + phase = Phase.Playing; phaseT = 0f + if (bonusNext) { bonus = BONUS_SECONDS; bonusNext = false; say(Hint.BONUS, 0); events = events or ChaosEvents.BONUS } + for (i in 0 until 3) fill(i) + startCurrent() + } + + private fun collect(p: ChaosPower) { + events = events or ChaosEvents.POWER + when (p) { + ChaosPower.Sweep -> { + for (s in 0 until Chan.SCREENS) if (!jammed[s]) meter[s] = 0f + for (i in 1 until 3) if (kind[i] == Chan.STATIC) kind[i] = liveChannel() + } + ChaosPower.AutoTune -> { autoLeft = 5; autoIn = AUTO_DELAY } + else -> { timedPower = p; powerLeft = p.seconds } + } + } + + private fun say(h: Int, side: Int) { hint = h; hintSide = side; hintT = 4f } + + // ---------- time ---------- + + fun step() { + if (phase == Phase.Over) return + ticks++ + val dt = STEP + clock += dt + phaseT += dt + if (lastT < 9f) lastT += dt + if (phase == Phase.Reward) { if (phaseT >= REWARD_SECONDS) skipReward(); return } + // The interruption waits for OK. + if (phase == Phase.Interlude) return + if (hintT > 0f) { hintT -= dt; if (hintT <= 0f) hint = Hint.NONE } + if (timedPower != null) { powerLeft -= dt; if (powerLeft <= 0f) { timedPower = null; powerLeft = 0f } } + if (bonus > 0f) { bonus -= dt; if (bonus <= 0f) { bonus = .0001f; endRound(); return } } + if (drift > 0f) drift = maxOf(0f, drift - dt) else if (stage >= 4 && bonus <= 0f) { driftIn -= dt; if (driftIn <= 0f) { drift = 8f; driftIn = 18f + rng.nextFloat() * 10f } } + if (autoLeft > 0) { + autoIn -= dt + if (autoIn <= 0f) { + autoIn = AUTO_DELAY; autoLeft-- + if (home() >= 0) send(home()) else ok() + return + } + } + if (!timed || timedPower == ChaosPower.Freeze) return + left -= dt + if (left <= 0f) { + // Left too long: it falls onto a screen as interference. + events = events or ChaosEvents.MISSED + streak = 0 + when (kind[0]) { + Chan.POWER -> {} + Chan.STATIC -> hurt(liveChannel(), .22f) + else -> hurt(home(), .22f) + } + if (phase == Phase.Playing) advance() + } + } + + fun takeEvents(): Int { val e = events; events = 0; return e } + + companion object { + const val STEP = 1f / 60f + const val STAGE_SIGNALS = 16 + const val BONUS_SECONDS = 15f + const val AUTO_DELAY = .35f + /** The four screens tuning in, the little ident and "And we're back on air!"; OK skips it. */ + const val REWARD_SECONDS = 3.2f + private val POWERS = ChaosPower.entries.toTypedArray() + } +} diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/ArcadeSessionTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/ArcadeSessionTest.kt index d6c6260e..9413f824 100644 --- a/android/app/src/test/java/tv/orbit/classic/arcade/ArcadeSessionTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/arcade/ArcadeSessionTest.kt @@ -84,6 +84,6 @@ class ArcadeSessionTest { assertTrue(resetAllowed(ResetAction.ResetLevelProgress, sky, "p", "p", false)) assertTrue(resetAllowed(ResetAction.ResetLevelProgress, hive, "p", "p", false)) // A coming-soon card has nothing to clear. - assertFalse(resetAllowed(ResetAction.ClearHighScores, ArcadeGames.ChannelChaos, "p", "p", false)) + assertFalse(resetAllowed(ResetAction.ClearHighScores, ArcadeGames.NightShift, "p", "p", false)) } } diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/KidsArcadeTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/KidsArcadeTest.kt index 24ce1e59..2567c8e7 100644 --- a/android/app/src/test/java/tv/orbit/classic/arcade/KidsArcadeTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/arcade/KidsArcadeTest.kt @@ -57,21 +57,21 @@ class KidsArcadeTest { } @Test fun pickRecentAndHighScoresFollowTheFilter() { - val chosen = kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Snake", "ChannelChaos")) + val chosen = kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Snake", "NightShift")) val visible = arcadeVisible(chosen) // Star Chase isn't chosen, so it can't be the pick. assertEquals("Snake", arcadePick(visible)!!.id) assertEquals("OrbMan", arcadePick(arcadeVisible(grown))!!.id) // Recent keeps only games this profile can still see and play. - assertEquals(listOf("Pairs", "Snake"), recentVisible(listOf("Blast", "Pairs", "ChannelChaos", "Snake", "Gone"), visible).map { it.id }) + assertEquals(listOf("Pairs", "Snake"), recentVisible(listOf("Blast", "Pairs", "NightShift", "Snake", "Gone"), visible).map { it.id }) assertNull(arcadePick(emptyList())) } @Test fun theFamilyLineSaysWhatKidsReallySee() { // The audit: "On: the games chosen for Kids" promised a choice that didn't exist. assertEquals("Off: no Arcade for Kids", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Off))) - assertEquals("Kids-suitable games: 8 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable))) - assertEquals("Chosen games: 2 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Sky", "ChannelChaos")))) + assertEquals("Kids-suitable games: 9 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable))) + assertEquals("Chosen games: 2 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Sky", "NightShift")))) assertEquals("Chosen games: none chosen yet, so no Arcade", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, emptySet()))) } @@ -79,7 +79,7 @@ class KidsArcadeTest { assertEquals(ArcadeGames.all.size, ArcadeGames.all.map { it.id }.toSet().size) assertEquals(5, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size) // BumbleHive and (Stage D) Orbi-Raiders are the Originals that play; every Classic does. - assertEquals(listOf("OrbiRaiders", "Hive"), ArcadeGames.originals.filter { it.launchable }.map { it.id }) + assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive"), ArcadeGames.originals.filter { it.launchable }.map { it.id }) assertTrue(ArcadeGames.classics.all { it.launchable }) ArcadeGames.all.forEach { g -> assertTrue(g.id, g.controls.isNotEmpty()); assertTrue(g.id, g.title.isNotBlank()); assertTrue(g.id, g.goal.isNotBlank()) diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt index 33b9e71e..fa913c06 100644 --- a/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt @@ -54,4 +54,15 @@ class TitleTextFitsTest { assertTrue("$label is ${"%.0f".format(w)} dp, room $room", w <= room) } } + + @Test fun channelChaosButtonsAndCardsFitAtTheLargestFontScale() { + val font = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(14f * 1.3f) + for ((label, column) in listOf("▶ Play" to 210, "? How to Play" to 210, "← Back to Arcade" to 210, "▶ Play Again" to 160, "← Back to Arcade" to 200)) { + val room = column - 2 * 12.0 - 4 + assertTrue("$label is ${"%.0f".format(width(font, label))} dp, room $room", width(font, label) <= room) + } + // The interruptions' captions wrap inside their 420 dp card; no single word may be wider than it. + 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) + } } diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosBalanceTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosBalanceTest.kt new file mode 100644 index 00000000..e1bb3fa2 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosBalanceTest.kt @@ -0,0 +1,38 @@ +package tv.orbit.classic.arcade.chaos + +import org.junit.Assert.assertTrue +import org.junit.Test +import tv.orbit.classic.arcade.Difficulty + +/** + * "Increasingly chaotic without becoming frustrating" (Paul). Three players through every difficulty: a young one (slow, + * often wrong), an ordinary one and a sharp one. Reported: how far each gets, and how often they clear the first bonus + * round (stage 3 and its bonus). Gentle must let the young player through the opening comfortably. + */ +class ChaosBalanceTest { + private class Player(val name: String, val think: Float, val slips: Float) + private val players = listOf(Player("young", 1.6f, .12f), Player("ordinary", 1.0f, .06f), Player("sharp", .6f, .03f)) + + private fun run(d: Difficulty, p: Player, seed: Int): Pair { + val sim = ChaosSim(d, seed) + val bot = ChaosBot(p.think, p.slips, seed) + var t = 0 + while (!sim.over && t < 60 * 60 * 20) { bot.tick(sim); sim.step(); t++ } + return sim.stage to t / 60f + } + + @Test fun theCurveOnEachDifficulty() { + val report = StringBuilder("Channel Chaos (bot, 24 seeds each):\n") + val firstBonus = HashMap() + for (d in Difficulty.entries) for (p in players) { + val runs = (1..24).map { run(d, p, it * 7919) } + val past3 = 100.0 * runs.count { it.first >= 4 } / runs.size + firstBonus["${d.name}/${p.name}"] = past3 + report.append("%-7s %-9s mean stage %5.1f | past the first bonus round %5.1f%% | mean minutes %5.1f%n".format( + d.title, p.name, runs.map { it.first }.average(), past3, runs.map { it.second }.average() / 60)) + } + println(report) + assertTrue(report.toString(), firstBonus["Gentle/young"]!! >= 75.0) + assertTrue(report.toString(), firstBonus["Gentle/young"]!! >= firstBonus["Normal/young"]!! && firstBonus["Normal/ordinary"]!! >= firstBonus["Tricky/ordinary"]!!) + } +} diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosBot.kt b/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosBot.kt new file mode 100644 index 00000000..7d14bf7a --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosBot.kt @@ -0,0 +1,29 @@ +package tv.orbit.classic.arcade.chaos + +/** + * A player for the tests: it looks at each new signal for [think] seconds, then presses; [slips] of the time it presses the + * wrong way (a different screen, or OK on a signal). It always answers the between-rounds OK. It allocates nothing. + */ +internal class ChaosBot(private val think: Float, private val slips: Float, seed: Int) { + private var waited = 0f + private var seen = -1L + private var s = seed.toLong() * 2654435761L + 1 + private fun roll(): Float { s = (s * 6364136223846793005L + 1442695040888963407L); return ((s ushr 33) and 0xFFFFFF).toFloat() / 0xFFFFFF } + + fun tick(sim: ChaosSim) { + if (sim.phase == Phase.Reward || sim.phase == Phase.Interlude) { if (sim.phaseT > .8f) sim.ok(); return } + if (sim.phase != Phase.Playing) return + // A new signal in the middle: the bot starts thinking again. + if (sim.arrivals != seen) { seen = sim.arrivals; waited = 0f } + waited += ChaosSim.STEP + if (waited < think) return + waited = -1e9f + val home = sim.home() + val slip = roll() < slips + when { + home < 0 -> if (slip) sim.send((roll() * 4).toInt().coerceIn(0, 3)) else sim.ok() + slip -> sim.send((home + 1 + (roll() * 3).toInt().coerceIn(0, 2)) % Chan.SCREENS) + else -> sim.send(home) + } + } +} diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosSimTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosSimTest.kt new file mode 100644 index 00000000..6e112d92 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/arcade/chaos/ChaosSimTest.kt @@ -0,0 +1,161 @@ +package tv.orbit.classic.arcade.chaos + +import org.junit.Assert.* +import org.junit.Test +import tv.orbit.classic.arcade.Difficulty + +/** Channel Chaos's rules: sending, static, jams, the curve, the rounds and the cast's interruptions. */ +class ChaosSimTest { + private fun sim(d: Difficulty = Difficulty.Normal, seed: Int = 5) = ChaosSim(d, seed) + + /** Plays [n] presses well: the right screen, or OK for static and power-ups; OK through the cards between rounds. */ + private fun playWell(s: ChaosSim, n: Int) { repeat(n) { if (s.phase == Phase.Playing) { if (s.home() >= 0) s.send(s.home()) else s.ok() } } } + + /** Plays well until [done], at most [limit] presses (so a test can never hang). */ + private fun until(s: ChaosSim, limit: Int = 500, done: () -> Boolean) { + var n = 0 + while (!done() && n++ < limit && !s.over) { if (s.phase == Phase.Playing) playWell(s, 1) else s.ok() } + } + + @Test fun eachChannelHasItsOwnColourAndShape() { + assertEquals(listOf("Orbit 1", "Riot", "Terra", "Tots"), Chan.names.toList()) + assertEquals(4, ChaosColours.channel.toSet().size) + assertEquals(androidx.compose.ui.graphics.Color(0xFF35D6F2), ChaosColours.channel[Chan.UP]) + } + + @Test fun theRightScreenScoresAndBuildsTheChainTheWrongOneAddsInterference() { + val s = sim() + s.send(s.home()) + assertEquals(10, s.score); assertEquals(1, s.streak) + repeat(7) { s.send(s.home()) } + assertEquals(3, s.chain) + val wrong = (s.home() + 1) % 4 + s.send(wrong) + assertEquals(1, s.chain); assertEquals(.3f, s.meter[wrong], 1e-4f) + } + + @Test fun oneNewThingAStage() { + val s = sim() + assertEquals(0f, s.staticChance(), 0f); assertEquals(0f, s.powerChance(), 0f); assertEquals(0f, s.mixedChance(), 0f) + until(s) { s.stage == 2 && s.phase == Phase.Playing } + assertTrue(s.staticChance() > 0f); assertEquals(0f, s.powerChance(), 0f) + until(s) { s.stage == 3 && s.phase == Phase.Playing } + assertTrue(s.powerChance() > 0f); assertEquals(0f, s.mixedChance(), 0f) + assertTrue(s.signalTime() < 3.4f) + } + + @Test fun okBinsStaticAndSendingStaticHurts() { + val s = sim(seed = 3) + s.kind[0] = Chan.STATIC + s.ok(); assertEquals(1, s.binned); assertEquals(5, s.score) + s.kind[0] = Chan.STATIC + s.send(Chan.LEFT); assertEquals(.3f, s.meter[Chan.LEFT], 1e-4f) + } + + @Test fun aFullMeterJamsAScreenAndThreeJammedEndTheRun() { + val s = sim() + for (side in 0 until 3) { + var g = 0 + while (!s.jammed[side] && g++ < 20) { s.kind[0] = Chan.STATIC; s.send(side) } + assertTrue(s.jammed[side]) + if (!s.over) for (i in 0 until 3) assertTrue(s.kind[i] != side) + } + assertTrue(s.over); assertEquals(Phase.Over, s.phase) + } + + @Test fun leftTooLongASignalFallsOntoItsScreen() { + val s = sim() + val home = s.home() + repeat((s.leftTotal / ChaosSim.STEP).toInt() + 3) { s.step() } + assertEquals(.22f, s.meter[home], 1e-4f) + } + + @Test fun gentleGivesTimeToThinkInTheFirstStages() { + val g = sim(Difficulty.Gentle) + assertFalse(g.timed) + val before = g.arrivals + repeat(60 * 60) { g.step() } + assertEquals("a minute and the signal's still waiting", before, g.arrivals) + assertEquals(0f, g.meter.sum(), 0f) + until(g) { g.stage == 3 && g.phase == Phase.Playing } + assertTrue(g.timed) + assertTrue(g.signalTime() > sim(Difficulty.Normal).signalTime()) + } + + @Test fun betweenRoundsTheRewardThenAnInterruptionThatWaitsForOk() { + val s = sim() + playWell(s, ChaosSim.STAGE_SIGNALS) + assertEquals(Phase.Reward, s.phase) + repeat((ChaosSim.REWARD_SECONDS * 60).toInt() + 2) { s.step() } + assertEquals(Phase.Interlude, s.phase) + repeat(60 * 30) { s.step() } + assertEquals("waits for OK", Phase.Interlude, s.phase) + s.send(Chan.UP); assertEquals(Phase.Interlude, s.phase) + s.ok(); assertEquals(Phase.Playing, s.phase); assertEquals(2, s.stage) + until(s) { s.phase == Phase.Reward } + s.ok(); assertEquals("OK skips the reward", Phase.Interlude, s.phase) + } + + @Test fun paulsTwoLinesAreThereAsWritten() { + val texts = Interludes.ALL.map { it.who to it.text } + assertTrue(texts.contains(Speaker.Blaze to "FASTER! WE'RE LOSING VIEWERS!")) + assertTrue(texts.contains(Speaker.Drift to "Oh. Was that supposed to go somewhere?")) + assertEquals("And we're back on air!", Interludes.BACK_ON_AIR) + assertTrue(Interludes.ALL.size >= 6) + } + + @Test fun blazesBonusRoundAfterEveryThirdStageThenBumbleRepairs() { + val s = sim() + until(s) { s.phase == Phase.Reward && s.interlude == Interludes.BONUS } + assertEquals(3, s.stage); assertEquals(Interludes.BONUS, s.interlude) + s.ok(); s.ok() + assertTrue(s.bonus > 0f) + assertEquals(0f, s.staticChance(), 0f) + s.meter.fill(0f) + val w = (s.home().coerceAtLeast(0) + 1) % 4; s.send(w); assertEquals("no harm in the bonus round", 0f, s.meter[w], 0f) + s.jammed[Chan.RIGHT] = true; s.meter[Chan.RIGHT] = 1f + repeat((ChaosSim.BONUS_SECONDS * 60).toInt() + 5) { s.step() } + assertEquals(Phase.Reward, s.phase) + assertEquals(Chan.RIGHT, s.repaired); assertFalse(s.jammed[Chan.RIGHT]) + assertEquals(Interludes.REPAIR, s.interlude); assertEquals(Speaker.Bumble, s.interlude.who) + s.ok(); s.ok(); assertEquals(4, s.stage) + } + + @Test fun powerUpsDoWhatTheySay() { + val s = sim() + until(s) { s.stage == 3 && s.phase == Phase.Playing } + s.kind[0] = Chan.POWER; s.power[0] = ChaosPower.Freeze; s.ok() + assertEquals(ChaosPower.Freeze, s.timedPower) + val a = s.arrivals + repeat(60 * 5) { s.step() } + assertEquals("frozen", a, s.arrivals) + s.meter[0] = .5f; s.kind[0] = Chan.POWER; s.power[0] = ChaosPower.Sweep; s.ok(); assertEquals(0f, s.meter[0], 0f) + s.kind[0] = Chan.POWER; s.power[0] = ChaosPower.Reception; s.ok() + if (s.home() >= 0) { val w = (s.home() + 1) % 4; s.send(w); assertEquals(0f, s.meter[w], 0f) } + s.kind[0] = Chan.POWER; s.power[0] = ChaosPower.AutoTune; s.ok() + val done = s.sent + s.binned + repeat(60 * 3) { s.step() } + assertTrue(s.sent + s.binned > done) + } + + @Test fun driftsMuddledSignalGoesToEitherScreenForDouble() { + val s = sim() + s.kind[0] = Chan.MIXED; s.mixA[0] = Chan.LEFT; s.mixB[0] = Chan.DOWN + assertTrue(s.accepts(Chan.LEFT) && s.accepts(Chan.DOWN) && !s.accepts(Chan.UP)) + s.send(Chan.DOWN); assertEquals(20, s.score) + } + + @Test fun steadyPlayAllocatesNothing() { + val s = ChaosSim(Difficulty.Normal, 9) + val bot = ChaosBot(.7f, .05f, 9) + fun tick() { bot.tick(s); s.step(); if (s.over) s.newRun() } + repeat(3_000) { tick() } + val mx = java.lang.management.ManagementFactory.getThreadMXBean() as com.sun.management.ThreadMXBean + val t = Thread.currentThread().id + val before = mx.getThreadAllocatedBytes(t) + repeat(10_000) { tick() } + val bytes = mx.getThreadAllocatedBytes(t) - before + println("Channel Chaos: 10,000 ticks allocated $bytes bytes") + assertTrue("allocated $bytes", bytes < 4 * 1024) + } +} diff --git a/docs/VERIFICATION-channel-chaos.md b/docs/VERIFICATION-channel-chaos.md new file mode 100644 index 00000000..05adaa7f --- /dev/null +++ b/docs/VERIFICATION-channel-chaos.md @@ -0,0 +1,42 @@ +# Channel Chaos prototype: verification (9 November 2026) + +Branch `arcade-channel-chaos` from `story-p1000` (`585ac72`), 0.110.14-chaos, versionCode 297. Not installed, no adb, nothing +pushed or merged. What it is: `docs/channel-chaos-prototype.md`. + +| | 0.110.13-story-p1000 (296) | 0.110.14-chaos (297) | +|---|---|---| +| Build (debug, release) | passed | passed | +| Kotlin unit tests | 965 run, 24 skipped, 0 failed (8 Nov) | **980 run, 24 skipped, 1 failed** (see below) | +| Lint | 0 errors, 87 warnings | **0 errors, 87 warnings** (no new ones) | +| Release APK | 47,892,063 bytes | 47,941,211 bytes (**+49,148**) | + +**The one failure is not Channel Chaos's.** `SmartSetupRegressionTest.sakuraIsBalancedFromItsOwnContentAndRepeatsFarLess` +(the channel planner) started failing after midnight on 9 November. It fails the same on the untouched `585ac72`, which +passed it the evening before, so it depends on today's date somewhere in the planner or the test. It needs a look on its +own, but has nothing to do with this branch. + +## New tests + +- `ChaosSimTest` (13): each channel its own colour and shape (Orbit 1 cyan); right screen scores and builds the chain, wrong + adds interference; one new thing a stage; OK bins static, sending static hurts; a full meter jams, three end the run, a + jammed screen's signals stop; a signal left too long falls on its screen; Gentle's untimed first stages; the reward then an + interruption that waits for OK (arrows do nothing, OK skips the reward); Paul's two lines as written; Blaze's bonus round + after stage 3 (no static, no harm) then Bumble's repair; the power-ups; Drift's muddled signal; **0 bytes a frame** (464 + over 10,000 ticks, from new runs). +- `ChaosBalanceTest` (1): **the bot on each difficulty**, three players (young 1.6 s and 12% slips, ordinary 1.0 s and 6%, + sharp 0.6 s and 3%), 24 seeds each: + +| | young | ordinary | sharp | +|---|---|---|---| +| Gentle | stage 11.0, 100% past the first bonus round | stage 42 (20 min cap) | stage 61 (cap) | +| Normal | stage 7.0, 100% | stage 11.0, 100% | stage 54 (cap) | +| Tricky | stage 5.0, 100% | stage 9.0, 100% | stage 13.2, 100% | + +- `TitleTextFitsTest` (+1): the title and result buttons and the interruption captions fit at font scale 1.3 (the result's + Back to Arcade was widened from 170 to 200 dp after it failed). +- Changed: `KidsArcadeTest` (9 Kids-suitable games now; Originals that play: Orbi-Raiders, Channel Chaos, BumbleHive) and + `ArcadeSessionTest` (a coming-soon example is now Night Shift). + +## Not checked + +Nothing seen running: drawing, focus, the cards, the ident and sound on the TV. diff --git a/docs/channel-chaos-prototype.md b/docs/channel-chaos-prototype.md new file mode 100644 index 00000000..28b90c5e --- /dev/null +++ b/docs/channel-chaos-prototype.md @@ -0,0 +1,97 @@ +# Channel Chaos (prototype, 8-9 November 2026) + +Branch `arcade-channel-chaos` from `story-p1000` (`585ac72`), version 0.110.14-chaos, versionCode 297. For testing only: +not installed. Built from the approved Stage B frames (`design/arcade/stage-b`: 30-title, 31-play, 32-bonus-round, +33-result, and the Channel Chaos row of the power-up family) and Paul's notes. + +## How it plays + +Signals drop into the tuning chute in the middle; the next two spiral in behind. The remote sends the one in the middle to +the screen in that direction: + +| Key | Screen | Colour and symbol | +|---|---|---| +| ▲ | Orbit 1 | cyan star (cyan, not orange, so it never looks like Tots) | +| ◀ | Riot | pink bolt (its channel mark) | +| ▶ | Terra | green leaf (its channel mark) | +| ▼ | Tots | amber sun (the Tots palette's sun) | + +OK bins grey static (the Orbi-Raiders static sprite's look). A wrong screen, static sent to a screen, OK on a real signal, +or a signal left too long puts interference on a screen; its name plate's meter turns red near full, a full one jams the +screen (its signals stop coming), and three jammed screens end the run. A right send clears a little interference. + +**Score**: 10 × chain × stage a match (chain ×1 to ×6, up by one every four in a row; any slip resets it). Binning static +is 5 × chain. Blaze's bonus round ×5, Double Points ×2, Drift's muddled signal ×2. + +## The curve (Paul: "increasingly chaotic without becoming frustrating") + +One new thing a stage, 16 signals a stage: + +- **Stage 1**: plain signals, slowly (3.4 s each). +- **Stage 2**: static arrives. +- **Stage 3**: power-ups ride the chute (send or OK catches them). +- **Stage 4 on**: Drift drifts past now and then, and his deliveries come muddled: half one channel, half another, either + screen takes it. +- **After every third stage**: Blaze's bonus round, 15 s, no static, no harm, every match ×5. +- Each stage the signals come 12% quicker (never under 0.75 s) and static grows (to 35% at most). + +Difficulty: **Gentle** has no timer at all for the first two stages ("give players time to think"), then signals wait 1.6× +as long, less static and less interference. **Tricky** is 0.78× the time, more static, more interference. + +The bot through each difficulty (24 seeds each; see VERIFICATION): a young player (1.6 s to decide, 12% slips) gets past the +first bonus round every time on Gentle and averages stage 11; on Normal an ordinary player (1 s, 6%) averages stage 11. + +## The cast (Paul's roles) + +- **Ollie** tries to keep the broadcast running: hosts, and his hints sit bottom left ("Static next! Press OK to bin it.", + "Riot's nearly jammed. Careful!"). The only one with a mouth. +- **Blaze** hosts the bonus rounds, happy-eyed, and shouts between rounds. +- **Drift** somehow delivers signals to the wrong place: his muddled two-channel signals, and his lines between rounds. +- **Bumble** rushes in to repair broken transmitters: after each bonus round, one jammed screen is repaired (back with a + little interference). + +All four are the cast library's own drawings (`drawOrbMascot`, `drawOrbChaser` for Blaze and Drift, `drawOrbBee`), drawn +once into small bitmaps; nothing is redrawn. Blaze, Drift and Bumble speak only in caption bubbles. + +## Between rounds + +1. **The reward** (3.2 s, OK skips): all four screens tune to their channels at once (no static, a soft glow), the little + Orbit ident in the chute (Orbit's own 5 KB logo, growing in; still under Reduce motion or Reduce flashing), and Ollie: + "And we're back on air!" +2. **An interruption** from the cast, waiting for OK (never mid-play). Paul's two as written, and more in the same spirit: + - Blaze: "FASTER! WE'RE LOSING VIEWERS!" + - Drift: "Oh. Was that supposed to go somewhere?" + - Blaze: "Bigger! Louder! MORE CHANNELS!" + - Drift: "I found this signal under a cloud. Is it yours?" + - Blaze: "Nobody blink. The ratings are watching." + - Drift: "I sent one to the moon. It seemed happy there." + - Ollie: "Steady hands. The viewers are with us." + - Before a bonus round, Blaze: "Bonus round! No static, just points. Go go go!" + - After Bumble's repair, Bumble: "Hold still, transmitter! Bumble's on it!" + +## Power-ups (the Stage B family's Channel Chaos row) + +One timed at a time. Channel Freeze (the middle signal stops falling, 8 s), Auto Tune (the next 5 send themselves), Signal +Sweep (clears interference on every working screen and static from the chute), Double Points (12 s), Perfect Reception (wrong +sends add no interference, 10 s). Each is its hexagon badge with its family's symbol. + +## Shared parts and rules + +The Arcade's pause menu, How to Play, Reduce motion (no shimmer, the ident still) and Reduce flashing (the send line steady), +the sound ceiling, per-profile saves (runs to High Scores as "Stage n", the best stage), Kids-suitable (in Kids' games, +Gentle by default). Back pauses (caught in the game's own key handler). One press is one send: a held key's repeats never +send again. The interruptions wait for OK; buttons spell their words out. + +## For Paul + +- **Title**: frame 30 has High Scores and Settings buttons on the title. They're left out here (the Arcade menu has both); + Play, How to Play and Back to Arcade remain. Add them if you want them on the game's own title. +- **Drift's role**: his muddled signal accepts either of its two channels for double points. If you meant something + trickier (a signal that looks like one channel but belongs to another), that's a small change. +- **Bumble**: repairs one jammed screen after each bonus round. More often, or as a power-up, are easy changes. +- **Endless**: the run goes on until three screens jam; there's no final stage yet. +- **Sound**: the existing Arcade cues only; no new sounds. + +## Not checked + +Nothing seen running: drawing, focus, the cards, the ident and sound on the TV are checked only by the compiler and tests.