diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index c26a43e5..b579a06b 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 = 309 - versionName = "0.118.0-new-originals" + versionCode = 310 + versionName = "0.119.0-orbit-rush" } 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 1329b431..db331280 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 @@ -122,6 +122,14 @@ internal object ArcadeGames { tv.orbit.classic.arcade.daily.ArcadeDailyScreen(it) } + // Paul's idea, 9 November 2026: a prototype to try for feel, plain shapes first. + val OrbitRush: ArcadeGame = GameDef("OrbitRush", "Orbit Rush", "Outrun the static storm", "Blaze races down three lanes through Asteroid Alley, a static storm behind.", Mascot.Blaze, + kidsSuitable = true, original = true, launchable = true, ScoreKind.Points, keepsLevels = false, legacyRecordKey = null, + listOf(Control("◀▶", "Change lane"), Control("▲", "Rise over"), Control("▼", "Dive under"), Control("OK", "Use the power-up"), BackPause), + "Red lane: change lanes. Yellow: rise. Cyan: dive.", listOf(GameSetting("sounds", "Sound effects"))) { + tv.orbit.classic.arcade.rush.OrbitRushScreen(it) + } + // Classics: the eight Kotlin games, unchanged, each in a thin wrapper. val OrbMan: ArcadeGame = GameDef("OrbMan", "Star Chase", "Maze chase starring Ollie", "Help Ollie clear the stars, and dodge Blaze, Zip, Drift and Luna.", Mascot.Ollie, kidsSuitable = true, original = false, launchable = true, ScoreKind.Points, keepsLevels = false, legacyRecordKey = "orb_man_best", @@ -152,7 +160,7 @@ internal object ArcadeGames { listOf(Control("◀▶▲▼", "Point"), Control("OK", "Pick up / put down"), Control("OK twice", "Send a card home"), Control("Back", "Put back, or pause")), "Klondike, one card at a time: build each suit home, ace to king.") { PatienceScreen(it) } - val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids, QuizNight, TestCardTangle, Codebreaker, Daily) + val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids, QuizNight, TestCardTangle, Codebreaker, Daily, OrbitRush) val classics = listOf(OrbMan, Blast, Sky, Snake, Blocks, Bricks, Pairs, Patience) val all = originals + classics diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/rush/OrbitRushScreen.kt b/android/app/src/main/java/tv/orbit/classic/arcade/rush/OrbitRushScreen.kt new file mode 100644 index 00000000..c047fbc4 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/arcade/rush/OrbitRushScreen.kt @@ -0,0 +1,233 @@ +package tv.orbit.classic.arcade.rush + +import android.view.KeyEvent +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.background +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.drawWithCache +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.geometry.CornerRadius +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.Path +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.graphicsLayer +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.tv.material3.Text +import tv.orbit.classic.Anton +import tv.orbit.classic.Motion +import tv.orbit.classic.R +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.ClassicResult +import tv.orbit.classic.arcade.ClassicTitle +import tv.orbit.classic.arcade.Control +import tv.orbit.classic.arcade.HowToPlayCard +import tv.orbit.classic.arcade.KeyFooter +import tv.orbit.classic.arcade.Mascot +import tv.orbit.classic.arcade.PauseWhenHidden +import tv.orbit.classic.arcade.RunEnd +import tv.orbit.classic.arcade.RunTracker +import tv.orbit.classic.arcade.gameKeys +import tv.orbit.classic.arcade.orbiteroids.OrbiteroidsArt +import tv.orbit.classic.arcade.previousLine +import tv.orbit.classic.arcade.raiders.FixedStep +import tv.orbit.classic.arcade.raiders.Pilot +import tv.orbit.classic.arcade.raiders.pilotFace +import tv.orbit.classic.ArcadeBackdrop +import tv.orbit.classic.starPath + +/** Orbit Rush's colours: plain shapes first (the prototype), each hazard its own colour and shape, unlike Orbiteroids'. */ +internal object RColours { + val Rock = Color(0xFFC2662D); val RockDark = Color(0xFF7A3A16) + val Low = Color(0xFF3F6FD8); val Panel = Color(0xFF9EC1FF) + val Tall = Color(0xFFE040A0) + val Star = Color(0xFFFFDE59) + val Shield = Color(0xFF22C3D8) + val Track = Color(0xFF16245A); val Edge = Color(0xFF3D63B8) + /** The warning on a lane before each hazard: red means change lane, yellow means rise, cyan means dive. */ + fun warn(kind: Int) = when (kind) { RKind.ROCK -> Color(0xFFFF6B6B); RKind.LOW -> Color(0xFFFFDE59); else -> Color(0xFF35D6F2) } +} + +private enum class RStage { Title, Play, Result } + +/** HUD numbers, read once a frame; Compose redraws only what changed. */ +private class RHud { + var score by mutableIntStateOf(0); var hull by mutableIntStateOf(RushSim.HULL); var stars by mutableIntStateOf(0) + var shieldHeld by mutableStateOf(false); var shieldSecs by mutableIntStateOf(0); var frame by mutableIntStateOf(0) + fun read(s: RushSim) { score = s.score; hull = s.hull; stars = s.stars; shieldHeld = s.shieldHeld; shieldSecs = kotlin.math.ceil(s.shieldFor).toInt(); frame++ } +} + +@Composable +internal fun OrbitRushScreen(play: ArcadePlay) { + val gameDef = ArcadeGames.OrbitRush + val latestPlay by rememberUpdatedState(play) + val calm = Motion.reduce + val steady = calm || play.reduceFlashing + val density = LocalDensity.current + val art = remember(density) { OrbiteroidsArt(pilotFace(Pilot.Blaze, 96, density)) } + val sim = remember { RushSim(play.difficulty) } + val hud = remember { RHud() } + val stepper = remember { FixedStep() } + var stage by remember { mutableStateOf(RStage.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) } + val tracker = remember { RunTracker { end -> latestPlay.onRunEnd(end) } } + fun endRun(finished: Boolean) { tracker.end(RunEnd(sim.score, finished, "${sim.distance.toInt()} m")) } + DisposableEffect(Unit) { onDispose { endRun(false) } } + LaunchedEffect(Unit) { play.audio.preload(R.raw.power_wide_orbit) } + fun startRun() { bestBefore = maxOf(latestPlay.best, bestBefore); sim.newRun(latestPlay.difficulty, System.nanoTime()); stepper.reset(); hud.read(sim); tracker.begin(); paused = false; stage = RStage.Play } + fun pause() { if (stage == RStage.Play && !paused) { paused = true; stepper.reset() } } + fun leave() { endRun(sim.over); latestPlay.onLeave() } + PauseWhenHidden(stage == RStage.Play && !paused) { pause() } + ArcadeGameLoop(running = stage == RStage.Play && !paused) { _, dt -> + val n = stepper.ticks(dt, paused) + var ev = 0 + for (i in 0 until n) { sim.step(); ev = ev or sim.events } + if (ev and (REvents.POWER or REvents.SHIELD_ON) != 0) latestPlay.audio.cue(R.raw.power_wide_orbit, .6f, soundsOn) + hud.read(sim) + if (sim.over) { endRun(true); stage = RStage.Result } + } + val focus = remember { FocusRequester() } + LaunchedEffect(stage, paused) { if (stage == RStage.Play && !paused) runCatching { focus.requestFocus() } } + BackHandler(stage == RStage.Play && !paused) { pause() } + + if (stage == RStage.Title) { + ClassicTitle(gameDef, ArcadeBackdrop.DeepSpace, tv.orbit.classic.OrbCharacter.Blaze.colour, "The storm's behind us. Go!", + listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"), timed = true, difficulty = play.difficulty, + refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, kicker = "AN ORBIT ARCADE ORIGINAL · PROTOTYPE", + mode = "Asteroid Alley", + note = "Blaze flies on his own. ◀▶ change lane round a rock, ▲ rises over a low satellite, ▼ dives under a tall signal gate. Each lane lights up before something arrives: red, change lane; yellow, rise; cyan, dive. Grab a shield and OK puts it on.") + if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false }) + return + } + // Moves act on the press (a held key repeats only for lanes, never for rise and dive). + val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == RStage.Play && !paused, pause = ::pause) { key, native -> + if (native.action != KeyEvent.ACTION_DOWN) return@gameKeys key != ArcadeKey.Other + when (key) { + ArcadeKey.Left -> sim.left(); ArcadeKey.Right -> sim.right() + ArcadeKey.Up -> if (native.repeatCount == 0) sim.rise(); ArcadeKey.Down -> if (native.repeatCount == 0) sim.dive() + ArcadeKey.Ok -> if (native.repeatCount == 0) sim.usePower() + else -> return@gameKeys false + } + true + } + Box(Modifier.fillMaxSize().then(keys)) { + Box(Modifier.fillMaxSize().rushSky()) + Canvas(Modifier.fillMaxSize()) { hud.frame; drawRush(art, sim, calm, steady) } + Column(Modifier.fillMaxSize().padding(start = 32.dp, end = 32.dp, top = 20.dp, bottom = 10.dp)) { + Row(Modifier.fillMaxWidth()) { + Column(Modifier.weight(1f)) { + Text("SCORE", color = ArcadeColours.Muted, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp) + Text("%,d".format(hud.score), color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 30.sp) + Text("★ ${hud.stars}", color = RColours.Star, fontSize = 16.sp, fontWeight = FontWeight.SemiBold) + } + Column(horizontalAlignment = Alignment.End) { + Text("HULL", color = ArcadeColours.Muted, fontSize = 16.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 2.sp) + Row(horizontalArrangement = Arrangement.spacedBy(3.dp)) { for (i in 0 until RushSim.HULL) Box(Modifier.size(28.dp, 10.dp).background(if (i < hud.hull) Color(0xFF4CD98A) else Color(0xFF1C2A5A), RoundedCornerShape(3.dp))) } + Spacer(Modifier.height(6.dp)) + Text(when { hud.shieldSecs > 0 -> "Orbit Shield on: ${hud.shieldSecs} s"; hud.shieldHeld -> "OK: Orbit Shield"; else -> "No power-up" }, + color = if (hud.shieldHeld || hud.shieldSecs > 0) RColours.Shield else ArcadeColours.Muted, fontSize = 15.sp, fontWeight = FontWeight.SemiBold) + } + } + Spacer(Modifier.weight(1f)) + KeyFooter(listOf(Control("◀▶", "Lane"), Control("▲", "Rise"), Control("▼", "Dive"), Control("OK", "Power-up"), Control("Back", "Pause")), note = "Asteroid Alley · prototype") + } + if (stage == RStage.Result) ClassicResult(gameDef, "ORBIT RUSH · ${sim.distance.toInt()} M THROUGH ASTEROID ALLEY", "SCORE", "%,d".format(sim.score), + newBest = sim.score > bestBefore && sim.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title), + detail = "${sim.stars} stars · ${sim.dodged} dodged · the static storm caught up", cheer = Mascot.Zip, onAgain = { endRun(sim.over); startRun() }, onBack = ::leave) + if (paused && stage == RStage.Play) ArcadePauseMenu(gameDef, "Orbit Rush · ${sim.distance.toInt()} m · ${"%,d".format(sim.score)}", + onResume = { paused = false; stepper.reset() }, onRestart = { endRun(false); startRun() }, onExit = ::leave, + sound = if (soundsOn) "Effects on" else "Effects off", onSound = { soundsOn = !soundsOn; latestPlay.setSetting("sounds", soundsOn) }) + } +} + +/** The sky and the track's lanes, drawn once in their own layer: only what moves is drawn each frame. */ +private fun Modifier.rushSky(): Modifier = graphicsLayer().drawWithCache { + val w = size.width; val h = size.height + val rnd = java.util.Random(7) + val stars = FloatArray(120 * 3) { k -> when (k % 3) { 0 -> rnd.nextFloat() * w; 1 -> rnd.nextFloat() * h * .4f; else -> .5f + rnd.nextFloat() * 1.5f } } + val horizon = h * HORIZON; val base = h + val track = Path().apply { moveTo(w / 2 - LANE_W * w * .2f * 1.5f, horizon); lineTo(w / 2 + LANE_W * w * .2f * 1.5f, horizon); lineTo(w / 2 + LANE_W * w * 1.5f, base); lineTo(w / 2 - LANE_W * w * 1.5f, base); close() } + onDrawBehind { + drawRect(Brush.verticalGradient(listOf(Color(0xFF040A1E), Color(0xFF0E1A48)), 0f, horizon)) + drawRect(Color(0xFF060C24), Offset(0f, horizon), Size(w, h - horizon)) + for (i in 0 until 120) drawCircle(Color.White.copy(alpha = .3f + stars[i * 3 + 2] / 5), stars[i * 3 + 2], Offset(stars[i * 3], stars[i * 3 + 1])) + drawPath(track, RColours.Track) + for (b in 0..3) { val off = b - 1.5f; drawLine(RColours.Edge, Offset(w / 2 + off * LANE_W * w * .2f, horizon), Offset(w / 2 + off * LANE_W * w, base), 2f) } + } +} + +/** Where the horizon sits, and a lane's width at the front (a share of the screen's width). */ +private const val HORIZON = .34f +private const val LANE_W = .2f + +/** The perspective: a thing at distance [z] is drawn at scale s (1 at Blaze, .2 at the horizon) and at height y. */ +private fun scaleAt(z: Float) = 1f / (1f + 4f * (z / FAR)) +private fun DrawScope.yAt(s: Float) = size.height * HORIZON + (size.height * .9f - size.height * HORIZON) * (s - .2f) / .8f +private fun DrawScope.xAt(laneX: Float, s: Float) = size.width / 2 + (laneX - 1f) * LANE_W * size.width * s + +private fun DrawScope.drawRush(art: OrbiteroidsArt, s: RushSim, calm: Boolean, steady: Boolean) { + val w = size.width; val h = size.height + // Dashes rushing past on the lane lines (still with Reduce motion). + val shift = if (calm) 0f else (s.distance % 10f) / 10f + for (b in 0..3) for (k in 0 until 8) { + val z = FAR * (1f - (k + shift) / 8f) + val sc = scaleAt(z); val off = b - 1.5f + drawCircle(RColours.Edge.copy(alpha = .4f + .6f * sc), 2f + 3f * sc, Offset(w / 2 + off * LANE_W * w * sc, yAt(sc))) + } + // Warnings: a lane lights in the colour of what's coming down it (steady with Reduce flashing). + for (i in 0 until RushSim.MAX) { + if (!s.on[i] || s.kind[i] > RKind.TALL || s.z[i] > WARN) continue + val a = if (steady) .35f else .25f + .15f * kotlin.math.sin(s.clock * 12f) + val sc = scaleAt(0f) + drawRect(RColours.warn(s.kind[i]).copy(alpha = a), Offset(xAt(s.laneOf[i].toFloat(), sc) - LANE_W * w * .5f, h * .9f), Size(LANE_W * w, h * .06f)) + } + // Far things first, so near ones are drawn over them. + for (pass in 0 until 2) for (i in 0 until RushSim.MAX) { + if (!s.on[i]) continue + val z = s.z[i] + if ((pass == 0) != (z > FAR / 2)) continue + val sc = scaleAt(z); val x = xAt(s.laneOf[i].toFloat(), sc); val y = yAt(sc); val u = LANE_W * w * sc + when (s.kind[i]) { + // A rock: a big chunky boulder filling the lane. + RKind.ROCK -> { drawCircle(RColours.RockDark, u * .42f, Offset(x, y - u * .3f)); drawCircle(RColours.Rock, u * .36f, Offset(x - u * .04f, y - u * .34f)); drawCircle(RColours.RockDark, u * .08f, Offset(x + u * .1f, y - u * .42f)) } + // A low satellite: a wide flat bar along the track (rise over it). + RKind.LOW -> { drawRect(RColours.Low, Offset(x - u * .45f, y - u * .16f), Size(u * .9f, u * .14f)); drawRect(RColours.Panel, Offset(x - u * .42f, y - u * .14f), Size(u * .3f, u * .1f)); drawRect(RColours.Panel, Offset(x + u * .12f, y - u * .14f), Size(u * .3f, u * .1f)) } + // A tall signal gate: two posts and a bar overhead, a gap underneath (dive under it). + RKind.TALL -> { drawRect(RColours.Tall, Offset(x - u * .45f, y - u * .9f), Size(u * .08f, u * .9f)); drawRect(RColours.Tall, Offset(x + u * .37f, y - u * .9f), Size(u * .08f, u * .9f)); drawRect(RColours.Tall, Offset(x - u * .45f, y - u * .9f), Size(u * .9f, u * .3f)) } + RKind.STAR -> drawPath(starPath(Offset(x, y - u * .3f), u * .16f, u * .07f, 0f), RColours.Star) + RKind.SHIELD -> { drawCircle(RColours.Shield, u * .18f, Offset(x, y - u * .3f)); drawCircle(Color.White, u * .18f, Offset(x, y - u * .3f), style = Stroke(u * .03f)) } + } + } + // Blaze's rocket: low when diving, high when rising, tinted for a moment when hit. + val bx = xAt(s.laneX, 1f) + val by = h * .82f + when (s.height) { RHeight.RISE -> -h * .12f; RHeight.DIVE -> h * .06f; else -> 0f } + val k = h / 260f + if (s.shieldFor > 0f) drawCircle(RColours.Shield.copy(alpha = .3f), 34f * k, Offset(bx, by)) + scale(k, k, Offset(bx, by)) { with(art) { ship(bx, by, 0f, s.hurtFor > 0f, if (calm) 1f else kotlin.math.sin(s.clock * 30f)) } } + // The static storm behind, closer as he's hit: a band of grey along the bottom (dots still with Reduce motion). + val band = h * (.06f + .14f * (1f - s.storm)) + drawRect(Brush.verticalGradient(listOf(Color.Transparent, Color(0xFF8D95AE).copy(alpha = .55f)), h - band, h), Offset(0f, h - band), Size(w, band)) + if (!calm) for (k2 in 0 until 40) { val sx = ((k2 * 97 + (s.clock * 400).toInt() * 13) % 1000) / 1000f * w; val sy = h - band * (((k2 * 37) % 100) / 100f); drawRect(Color.White.copy(alpha = .35f), Offset(sx, sy), Size(3f, 2f)) } +} diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/rush/RushSim.kt b/android/app/src/main/java/tv/orbit/classic/arcade/rush/RushSim.kt new file mode 100644 index 00000000..92bcb2a2 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/arcade/rush/RushSim.kt @@ -0,0 +1,135 @@ +package tv.orbit.classic.arcade.rush + +import tv.orbit.classic.arcade.Difficulty + +/** + * Orbit Rush (prototype, 9 November 2026, from Paul's idea): Blaze flies forward on his own down three lanes through + * Asteroid Alley, a static storm close behind. ◀▶ change lane, ▲ rises over a low satellite, ▼ dives under a tall + * signal gate; rocks block a lane at every height, so only a lane change gets round one. Stars to collect, and one + * power-up (Orbit Shield) held until OK. Three hull bars. + * + * 2.5D: the sim works in lanes and distance ahead; the screen draws it in perspective. Fixed 60 Hz steps over pooled + * arrays: nothing is made while it runs (checked by RushSimTest). + */ +internal const val RSTEP = 1f / 60f +internal const val LANES = 3 +/** How far ahead things appear, and where they're first shown with a warning on their lane. */ +internal const val FAR = 100f +internal const val WARN = 55f + +internal object RKind { const val ROCK = 0; const val LOW = 1; const val TALL = 2; const val STAR = 3; const val SHIELD = 4 } + +/** Blaze's height: level, rising over a low thing, or diving under a tall one. */ +internal object RHeight { const val LEVEL = 0; const val RISE = 1; const val DIVE = 2 } + +internal object REvents { const val STAR = 1; const val HIT = 2; const val DODGE = 4; const val POWER = 8; const val SHIELD_ON = 16; const val OVER = 32 } + +internal class RushSim(var difficulty: Difficulty = Difficulty.Normal, seed: Long = 1) { + private var rnd = java.util.Random(seed) + + // ---------- Blaze ---------- + /** The lane he's in or heading for (0 left, 1 middle, 2 right), and where he's drawn, sliding between lanes. */ + var lane = 1; var laneX = 1f + var height = RHeight.LEVEL; var heightFor = 0f + var hull = HULL; var hurtFor = 0f + /** Orbit Shield: held until OK, then on for a while. */ + var shieldHeld = false; var shieldFor = 0f + + // ---------- the alley ---------- + val kind = IntArray(MAX); val laneOf = IntArray(MAX); val z = FloatArray(MAX); val on = BooleanArray(MAX) + var distance = 0f; var speed = 0f; var stars = 0; var dodged = 0 + var over = false; var clock = 0f + private var spawnIn = 0f + /** The static storm: how far behind (1 far, 0 on his tail); it closes in when he's hit and drifts back as he flies on. */ + var storm = 1f + var events = 0 + + val score get() = distance.toInt() + stars * 10 + + private val pace get() = when (difficulty) { Difficulty.Gentle -> .78f; Difficulty.Normal -> 1f; Difficulty.Tricky -> 1.18f } + + fun newRun(d: Difficulty, seed: Long) { + difficulty = d; rnd = java.util.Random(seed) + lane = 1; laneX = 1f; height = RHeight.LEVEL; heightFor = 0f; hull = HULL; hurtFor = 0f; shieldHeld = false; shieldFor = 0f + on.fill(false); distance = 0f; speed = START_SPEED * pace; stars = 0; dodged = 0; over = false; clock = 0f; spawnIn = 1.2f; storm = 1f; events = 0 + } + + // ---------- the remote ---------- + fun left() { if (!over && lane > 0) lane-- } + fun right() { if (!over && lane < LANES - 1) lane++ } + fun rise() { if (!over) { height = RHeight.RISE; heightFor = MOVE_TIME } } + fun dive() { if (!over) { height = RHeight.DIVE; heightFor = MOVE_TIME } } + /** OK: the held power-up goes on. */ + fun usePower(): Boolean { if (over || !shieldHeld) return false; shieldHeld = false; shieldFor = SHIELD_TIME; events = events or REvents.SHIELD_ON; return true } + + fun step() { + events = 0 + if (over) return + val dt = RSTEP + clock += dt + // Faster the further he goes, to a limit. + speed = minOf(MAX_SPEED, (START_SPEED + distance * .012f)) * pace + distance += speed * dt + // Lanes slide quickly; a rise or dive lasts a moment, then he levels out. + laneX += (lane - laneX) * minOf(1f, LANE_SNAP * dt) + if (kotlin.math.abs(lane - laneX) < .01f) laneX = lane.toFloat() + if (heightFor > 0f) { heightFor -= dt; if (heightFor <= 0f) height = RHeight.LEVEL } + if (hurtFor > 0f) hurtFor -= dt + if (shieldFor > 0f) shieldFor -= dt + storm = minOf(1f, storm + dt * .02f) + // Everything comes towards him; whatever reaches him is met. + for (i in 0 until MAX) { + if (!on[i]) continue + z[i] -= speed * dt + if (z[i] > 0f) continue + on[i] = false + if (laneOf[i] != lane) { if (kind[i] <= RKind.TALL) { dodged++; events = events or REvents.DODGE }; continue } + when (kind[i]) { + RKind.STAR -> { stars++; events = events or REvents.STAR } + RKind.SHIELD -> { shieldHeld = true; events = events or REvents.POWER } + RKind.ROCK -> meet() + RKind.LOW -> if (height == RHeight.RISE) { dodged++; events = events or REvents.DODGE } else meet() + RKind.TALL -> if (height == RHeight.DIVE) { dodged++; events = events or REvents.DODGE } else meet() + } + } + // A new row: always at least one way through. + spawnIn -= dt + if (spawnIn <= 0f) { spawnRow(); spawnIn = rowGap() } + } + + /** Seconds between rows: shorter as the speed builds; Gentle leaves more room, Tricky less. */ + private fun rowGap() = (when (difficulty) { Difficulty.Gentle -> 1.35f; Difficulty.Normal -> 1.05f; Difficulty.Tricky -> .85f } - distance * .00004f).coerceAtLeast(.6f) + + private fun meet() { + if (hurtFor > 0f || shieldFor > 0f) { dodged++; return } + hull--; hurtFor = HURT_TIME; storm = maxOf(0f, storm - .34f) + events = events or REvents.HIT + if (hull <= 0) { hull = 0; over = true; events = events or REvents.OVER } + } + + private fun spawn(k: Int, laneAt: Int) { + for (i in 0 until MAX) if (!on[i]) { on[i] = true; kind[i] = k; laneOf[i] = laneAt; z[i] = FAR; return } + } + + /** + * A row of hazards: one or two (never all three blocked by rocks), so a lane is always free or a rise or dive gets + * through; stars in a free lane now and then, and a shield once in a while. + */ + private fun spawnRow() { + val hazards = if (difficulty == Difficulty.Gentle || rnd.nextInt(3) != 0) 1 else 2 + val free = rnd.nextInt(LANES) + var placed = 0 + for (l in 0 until LANES) { + if (l == free || placed >= hazards) continue + val k = when (rnd.nextInt(3)) { 0 -> RKind.ROCK; 1 -> RKind.LOW; else -> RKind.TALL } + spawn(k, l); placed++ + } + if (rnd.nextInt(3) == 0) spawn(if (rnd.nextInt(14) == 0) RKind.SHIELD else RKind.STAR, free) + } + + companion object { + const val MAX = 48; const val HULL = 3 + const val START_SPEED = 46f; const val MAX_SPEED = 95f + const val LANE_SNAP = 22f; const val MOVE_TIME = .7f; const val HURT_TIME = 1f; const val SHIELD_TIME = 6f + } +} 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 98c7366d..2baadb3b 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 @@ -16,7 +16,7 @@ class KidsArcadeTest { @Test fun grownUpsSeeEveryGame() { assertEquals(ArcadeGames.all.map { it.id }, ids(grown)) - assertEquals(17, ids(grown).size) + assertEquals(18, ids(grown).size) // A grown-up's Arcade for Kids setting means nothing. assertEquals(ArcadeGames.all.map { it.id }, ids(grown.withKidsArcade(KidsArcade.Off))) assertEquals(ArcadeGames.all.map { it.id }, ids(null)) @@ -70,16 +70,16 @@ class KidsArcadeTest { @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: 15 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable))) + assertEquals("Kids-suitable games: 16 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable))) assertEquals("Chosen games: 2 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Sky", "Retired")))) assertEquals("Chosen games: none chosen yet, so no Arcade", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, emptySet()))) } @Test fun everyGameIsDescribed() { assertEquals(ArcadeGames.all.size, ArcadeGames.all.map { it.id }.toSet().size) - assertEquals(9, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size) + assertEquals(10, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size) // All five Originals play now (Orbiteroids, the last, 9 November 2026); every Classic does. - assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle", "Codebreaker", "ArcadeDaily"), ArcadeGames.originals.filter { it.launchable }.map { it.id }) + assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle", "Codebreaker", "ArcadeDaily", "OrbitRush"), 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/rush/RushSimTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/rush/RushSimTest.kt new file mode 100644 index 00000000..ac59156f --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/arcade/rush/RushSimTest.kt @@ -0,0 +1,92 @@ +package tv.orbit.classic.arcade.rush + +import org.junit.Assert.* +import org.junit.Test +import tv.orbit.classic.arcade.Difficulty + +class RushSimTest { + private fun fresh(d: Difficulty, seed: Long = 1) = RushSim(d).also { it.newRun(d, seed) } + + /** + * A careful player with a reaction time: acts only once a hazard's lane warning is showing and [reaction] seconds have + * passed since it first could have; rocks get a lane change to a lane clear of the next thing coming, low things a + * rise, tall ones a dive, timed for the moment they arrive. + */ + private fun bot(s: RushSim, reaction: Float) { + var nearest = -1 + for (i in 0 until RushSim.MAX) if (s.on[i] && s.laneOf[i] == s.lane && s.kind[i] <= RKind.TALL && (nearest < 0 || s.z[i] < s.z[nearest])) nearest = i + if (nearest < 0) return + val seen = (WARN - s.z[nearest]) / s.speed // seconds since its warning came on + if (seen < reaction) return + val t = s.z[nearest] / s.speed // seconds until it arrives + when (s.kind[nearest]) { + RKind.ROCK -> { + // The lane whose next hazard is furthest off. + var best = s.lane; var room = -1f + for (l in 0 until LANES) if (kotlin.math.abs(l - s.lane) == 1 || l == s.lane) { + var near = Float.MAX_VALUE + for (i in 0 until RushSim.MAX) if (s.on[i] && s.laneOf[i] == l && s.kind[i] <= RKind.TALL) near = minOf(near, s.z[i]) + if (l != s.lane && near > room) { room = near; best = l } + } + if (best < s.lane) s.left() else if (best > s.lane) s.right() + } + RKind.LOW -> if (t < .45f && s.height != RHeight.RISE) s.rise() + RKind.TALL -> if (t < .45f && s.height != RHeight.DIVE) s.dive() + } + } + + @Test fun everyHazardCanBeDodgedInTimeOnEveryDifficulty() { + // Three minutes each, at the fastest the run gets: a player reacting within a quarter of a second takes no hits. + for (d in Difficulty.entries) for (seed in 1L..6L) { + val s = fresh(d, seed); var hits = 0 + repeat(180 * 60) { bot(s, .25f); s.step(); if (s.events and REvents.HIT != 0) hits++ } + assertEquals("$d seed $seed: hits", 0, hits); assertFalse(s.over) + assertTrue(s.dodged > 50) + } + } + + @Test fun theWarningComesSoonEnoughEvenAtFullSpeed() { + // From the warning to arrival is at least half a second at the top speed on Tricky: time to see and press. + val top = RushSim.MAX_SPEED * 1.18f + assertTrue(WARN / top >= .45f) + // And rows never come so close that a lane change and a rise can't both be done between them. + assertTrue(.6f >= RushSim.MOVE_TIME * .8f) + } + + @Test fun eachHazardWantsItsOwnMove() { + fun meet(kind: Int, act: (RushSim) -> Unit): Int { + val s = fresh(Difficulty.Normal); for (i in 0 until RushSim.MAX) s.on[i] = false + s.on[0] = true; s.kind[0] = kind; s.laneOf[0] = 1; s.z[0] = .1f + act(s); s.step(); return s.hull + } + assertEquals(RushSim.HULL - 1, meet(RKind.ROCK) { it.rise() }) // a rock: rising doesn't help + assertEquals(RushSim.HULL, meet(RKind.ROCK) { it.left() }) + assertEquals(RushSim.HULL, meet(RKind.LOW) { it.rise() }); assertEquals(RushSim.HULL - 1, meet(RKind.LOW) { it.dive() }) + assertEquals(RushSim.HULL, meet(RKind.TALL) { it.dive() }); assertEquals(RushSim.HULL - 1, meet(RKind.TALL) { it.rise() }) + } + + @Test fun theShieldIsHeldUntilOkAndThenTakesHits() { + val s = fresh(Difficulty.Normal); for (i in 0 until RushSim.MAX) s.on[i] = false + s.on[0] = true; s.kind[0] = RKind.SHIELD; s.laneOf[0] = 1; s.z[0] = .1f; s.step() + assertTrue(s.shieldHeld); assertTrue(s.usePower()); assertFalse(s.usePower()) + s.on[1] = true; s.kind[1] = RKind.ROCK; s.laneOf[1] = 1; s.z[1] = .1f; s.step() + assertEquals(RushSim.HULL, s.hull) + } + + @Test fun threeHitsEndTheRunAndTheStormClosesIn() { + val s = fresh(Difficulty.Normal); var t = 0 + while (!s.over && t < 60 * 120) { s.step(); t++ } // nobody steering + assertTrue(s.over); assertEquals(0, s.hull); assertTrue(s.storm < 1f) + } + + @Test fun nothingIsAllocatedWhileItRuns() { + val s = fresh(Difficulty.Normal, 3) + repeat(2_000) { bot(s, .25f); s.step() } + val mx = java.lang.management.ManagementFactory.getThreadMXBean() as com.sun.management.ThreadMXBean + val before = mx.getThreadAllocatedBytes(Thread.currentThread().id) + repeat(10_000) { bot(s, .25f); s.step(); if (s.over) s.newRun(Difficulty.Normal, 4) } + val bytes = mx.getThreadAllocatedBytes(Thread.currentThread().id) - before + println("Orbit Rush: 10,000 ticks allocated $bytes bytes") + assertTrue("allocated $bytes", bytes < 8 * 1024) + } +} diff --git a/docs/orbit-rush.md b/docs/orbit-rush.md new file mode 100644 index 00000000..ada3f37b --- /dev/null +++ b/docs/orbit-rush.md @@ -0,0 +1,52 @@ +# Orbit Rush: prototype (0.119.0, versionCode 310, 9 November 2026) + +From Paul's idea, built as the small prototype he agreed to: to try for feel on the TV before any artwork. On top of +0.118.0 (309, installed downstairs). Not installed; nothing seen running. + +## What's in it + +- **The run:** Blaze flies forward on his own down **three lanes** through **Asteroid Alley**, a static storm behind. He + gets a little quicker the further he goes. +- **The remote:** ◀▶ change lane, ▲ rises, ▼ dives, OK uses the power-up, Back pauses (nothing is held, so Back by context + is a plain pause). Every move acts on the press. Lanes repeat on a held key; rise and dive don't. +- **Three hazards**, plain shapes in their own colours (nothing like Orbiteroids' grey rocks and debris): + +| Hazard | Shape | Way past it | +|---|---|---| +| Rock | an orange boulder | it blocks its lane at every height, so change lane | +| Low satellite | a wide blue bar along the track | rise over it | +| Tall signal gate | pink posts and a bar overhead | dive under it | + +- **Lane warnings:** before each hazard its lane lights in a colour, red for change lane, yellow for rise, cyan for dive. + It's shown at least half a second before arrival even at the top speed on Tricky. +- **Never boxed in:** every row has a free lane or a way over or under. +- **The power-up:** Orbit Shield is picked up and held, and OK puts it on for 6 seconds, during which hits bounce off. +- **Stars:** collected for score (10 each). +- **The static storm:** three hull bars; each hit costs one and brings the storm closer (a grey band along the bottom). + The third ends the run. +- **Difficulty:** Gentle is slower with one hazard a row and more room between rows; Tricky is quicker with closer rows + and two hazards more often. +- **Reduce motion:** the dashes and the storm's static hold still. **Reduce flashing:** the warnings are steady. +- **2.5D:** a perspective track in Canvas. + - The sky and the lanes are drawn once in their own layer. + - Each frame draws the moving dashes, the hazards (scaled by distance, far ones first) and Blaze's rocket (Orbi-Raiders' + rocket with Blaze in the porthole). +- **Screens:** the shared title (with "AN ORBIT ARCADE ORIGINAL · PROTOTYPE"), pause and result. +- **Saves:** its own High Scores per profile (points: distance plus stars). Kids-suitable. + +## Checks (`RushSimTest`) + +- **A bot can dodge everything:** a careful player reacting a quarter of a second after each warning takes **no hits in + three minutes** on Gentle, Normal and Tricky, six runs each. +- **Each hazard wants its own move:** rising doesn't get past a rock, and diving doesn't get under a low satellite. +- The shield is held until OK, then takes a hit. +- Three hits end the run, and the storm closes in. +- **0 bytes allocated over 10,000 steps.** +- **Unit tests:** 1,081 run, 24 skipped, 0 failed. +- **Lint:** 0 errors, 87 warnings (none new). +- **Release APK:** 48,268,891 bytes (+16,376 on 0.118.0). + +## For after Paul's try + +Artwork, more regions (Broadcast Boulevard, The Static Zone, The Forbidden Frequency's 999 portal), a choice of pilot +with their own abilities, more power-ups, and sounds.