Channel Chaos: playable prototype (0.110.14-chaos, versionCode 297)
The Channel Chaos card is now a game, from Stage B frames 30-33 and Paul's notes: send each signal from the chute to its screen (Orbit 1 cyan star, Riot pink bolt, Terra green leaf, Tots amber sun), OK bins static, three jammed screens end the run. One new thing a stage (static, power-ups, Drift's muddled signals), no timer for Gentle's first two stages, Blaze's bonus round every third stage, Bumble repairing a jammed screen after it. Between rounds the screens tune in with a little Orbit ident and 'And we're back on air!', then a cast interruption that waits for OK (Paul's two lines as written). Cast drawn from the cast library, unchanged. Shared pause, How to Play, result, Reduce motion and flashing, per-profile saves, Kids-suitable. 15 new tests incl. a bot on each difficulty and 0 bytes a frame. One planner test (SmartSetupRegressionTest) fails since midnight on the base commit too: date-dependent, unrelated. Docs: docs/channel-chaos-prototype.md and its VERIFICATION. Not installed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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<ChaosPower?>(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))
|
||||
}
|
||||
}
|
||||
@@ -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<TextLayoutResult> = 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)
|
||||
}
|
||||
}
|
||||
@@ -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<ChaosPower>(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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user