The pack
jetpackRunner2d
function jetpackRunner2d(): Pack<{ jetpackRunner: JetpackRunnerApi }>
The jetpack-runner-2d pack: game.jetpackRunner, Jetpack Joyride's rules on runner-core. No options.
Helpers
createJetpackAutopilot
function createJetpackAutopilot(game: JetpackRunner, options: JetpackAutopilotOptions = {}): JetpackAutopilot
A jetpack run's autopilot. It only reads game; give its moves to game.input.
createJetpackRunner
function createJetpackRunner(options: JetpackRunnerOptions = {}): JetpackRunner
Start a jetpack run. Throws, with every fault, on options it refuses.
jetpackChunks
function jetpackChunks(options: { height?: number } = {}): RunnerChunk<JetpackItem>[]
Jetpack Joyride's corridor as chunks, for any corridor height: zappers level, upright, slanted, in tunnels, in stairs, spinning and sliding; lasers in pairs and with one gap; tracking missiles alone and in volleys; coin blocks and waves; vehicle tokens. Harder ones come further along. Heights are fractions of the corridor's.
jetpackMotion
const jetpackMotion: JetpackMotion
The runner's jetpack.
jetpackVehicles
const jetpackVehicles: Record<string, JetpackMotion>
The built-in vehicles.
validateJetpackRunner
function validateJetpackRunner(options: JetpackRunnerOptions = {}): string[]
Check a jetpack run's options and chunks. Empty when it can be run.
Types
JetpackAutopilot
interface JetpackAutopilot
A player that picks the moves.
next(): JetpackMove[]— The moves to giveinputnow. Call it before each step.
JetpackAutopilotOptions
interface JetpackAutopilotOptions
How the autopilot looks ahead.
horizon?: number— Seconds a plan must live through. Default 1.3.beyond?: number— Seconds it looks on past that. Default 0.7.levels?: number[]— Heights it holds, as fractions of the corridor. Default 5 from floor to ceiling.then?: number— When a plan's second height (or a tap) comes. Default 0.4 s.every?: number— Seconds of run between decisions. Default 0.1.
JetpackCoins
interface JetpackCoins
Coins in a block, a line or a wave.
kind: 'coins'— Always'coins': what tells this item from the other kinds in a chunk.at: number— Where the first column is along the chunk.y: number— The height of the bottom row.cols?: number— Columns. Default 1.rows?: number— Rows. Default 1.every?: number— Spacing. Default 1.wave?: number— A wave this high, one sway across the columns. Default 0.
JetpackEvent
type JetpackEvent = | RunnerEvent<JetpackItem> | { kind: 'laser-warn'; id: string; y: number } | { kind: 'laser-fire'; id: string; y: number } | { kind: 'missile-warn'; id: string } | { kind: 'missile-launch'; id: string; y: number } | { kind: 'vehicle'; vehicle: string } | { kind: 'eject'; vehicle: string } | { kind: 'flip'; down: boolean } | { kind: 'hit'; what: string; id: string } | { kind: 'pickup'; id: string; x: number; y: number; vehicle?: string }
Something that happened in a jetpack run.
JetpackItem
type JetpackItem = JetpackZapper | JetpackLaser | JetpackMissile | JetpackCoins | JetpackToken
What a jetpack chunk holds.
JetpackLaser
interface JetpackLaser
A laser: when the runner reaches it, a beam across the whole screen warns, then fires, then goes.
kind: 'laser'— Always'laser': what tells this item from the other kinds in a chunk.at: number— Where along the chunk it is set off.y: number— The beam's height.warn?: number— Seconds of warning. Default 1.4.fire?: number— Seconds it fires. Default 1.
JetpackLaserView
interface JetpackLaserView
A laser, as drawn.
id: string— Stable while the laser is on: its chunk's index, a colon, then its place in the chunk's items.y: number— The beam's height above the floor, in world units.state: 'warn' | 'fire'—'warn'while the beam is only a warning,'fire'while it is deadly.left: number— Seconds until the current state ends: the warning gives way to firing, then firing ends.
JetpackMissile
interface JetpackMissile
A missile: set off when the runner reaches it; a warning at the screen's edge tracks its height, then it flies in.
kind: 'missile'— Always'missile': what tells this item from the other kinds in a chunk.at: number— Where along the chunk it is set off.y?: number— Fly in at this height instead of tracking the runner.warn?: number— Seconds of warning: tracking, then a moment held. Default 1.3.speed?: number— Its speed, units a second, against the corridor. Default 28.
JetpackMissileView
interface JetpackMissileView
A missile or its warning, as drawn.
id: string— Stable while the missile is out: its chunk's index, a colon, then its place in the chunk's items.x: number— Distance along the corridor, in world units; while warning, the screen's edge ahead of the runner.y: number— Height above the floor, in world units; while warning it may still be following the runner.state: 'warn' | 'fly'—'warn'while the warning shows at the screen's edge,'fly'once the missile is coming in.left: number— Seconds of warning remaining; 0 once it flies.
JetpackMotion
interface JetpackMotion
How the runner (or a vehicle) moves.
mode: 'thrust' | 'flip' | 'jump' | 'flap'—'thrust': hold to rise (the jetpack).'flip': a tap turns gravity over.'jump': a tap jumps from the floor, and holding floats down slowly.'flap': a tap flaps upward.gravity: number— Gravity, units a second squared.thrust?: number— Thrust while held ('thrust').impulse?: number— The speed a jump or a flap gives.maxSpeed: number— The fastest rise and fall.height: number— Height of the body.width: number— Width of the body.
JetpackMove
type JetpackMove = 'hold' | 'release' | 'tap'
A move: hold or let go of the jetpack, or a tap for a vehicle.
JetpackRunner
interface JetpackRunner
A jetpack run.
readonly run: Runner<JetpackItem>— runner-core's run under it.readonly state: JetpackRunnerState— Where the runner is.readonly options: Readonly<{ height: number; screenAhead: number; jetpack: JetpackMotion; vehicles: Record<string, JetpackMotion> }>— The options, defaults filled in.input(move: JetpackMove): void— Hold or let go of the thrust, or tap (a vehicle's flip, jump or flap).motion(): JetpackMotion— How the runner moves now: its jetpack, or its vehicle's.step(dt: number): void— Advancedtseconds, in fixed steps of 1/120 s.view(): JetpackView— What is where.drain(): JetpackEvent[]— Events since the last call.snapshot(): JetpackRunnerSave— The run as plain JSON.restore(save: JetpackRunnerSave): void— Pick up a saved run made with the same options.clone(): JetpackRunner— A separate run with the same options at the same point.
JetpackRunnerApi
interface JetpackRunnerApi
What the jetpack-runner-2d pack adds to a game: game.jetpackRunner.
create: typeof createJetpackRunner— Start a jetpack run.validate: typeof validateJetpackRunner— Check a jetpack run's options; empty when it can be run.chunks: typeof jetpackChunks— The built-in corridor as chunks.motion: typeof jetpackMotion— The runner's jetpack.vehicles: typeof jetpackVehicles— The built-in vehicles.autopilot: typeof createJetpackAutopilot— A player that looks ahead, for an attract mode or a test.
JetpackRunnerOptions
interface JetpackRunnerOptions
A jetpack run's options: the corridor, the runner, the vehicles, and runner-core's run.
height?: number— The corridor's height. Default 9.screenAhead?: number— How far ahead of the runner the screen reaches: where missiles come from. Default 16.jetpack?: Partial<JetpackMotion>— How the runner moves on its own jetpack. DefaultjetpackMotion.vehicles?: Record<string, JetpackMotion>— The vehicles tokens give, by name. DefaultjetpackVehicles.chunks?: RunnerChunk<JetpackItem>[]— The chunks. DefaultjetpackChunks({ height }).opening?: string[]— Chunk ids played first. Default['start']with the built-in chunks.powerUps?: Record<string, RunnerPowerUp>— Power-ups besides the vehicles (a magnet'sdata.reach, a doubler'smultiplier). Default none.run?: Omit<RunnerOptions<JetpackItem>, 'chunks' | 'opening' | 'powerUps' | 'hits'>— runner-core's options for the run.
JetpackRunnerSave
interface JetpackRunnerSave
A jetpack run saved as plain JSON.
run: RunnerSave— runner-core's save of the run under it.state: JetpackRunnerState— The runner's state.clock: number— Seconds the motor has run, which sets how far zappers have spun and slid.taken: string[]— Ids of the coins and tokens already picked up.lasers: Laser[]— Lasers now warning or firing, with the seconds each has been on.missiles: Missile[]— Missiles now warning or flying, with the seconds each has been out.
JetpackRunnerState
interface JetpackRunnerState
Where the runner is and what it is doing.
x: number— Distance along the corridor: runner-core's.y: number— Height of his feet (of his head, flipped).vy: number— Vertical speed.holding: boolean— Holding the thrust.grounded: boolean— On the floor (or the ceiling, flipped).flipped: boolean— Gravity turned over (a gravity suit).vehicle: string | null— The vehicle he is in, or null.tumble: number— After a hit ends the run: how far he tumbled on.
JetpackThingView
interface JetpackThingView
A coin or a token, as drawn.
id: string— Stable while the thing is in the corridor: a token's is its chunk index and item place; a coin's adds its column and row.x: number— Distance along the corridor, in world units.y: number— Height above the floor, in world units.vehicle?: string— For a token, the name of the vehicle it gives; absent on a coin.
JetpackToken
interface JetpackToken
A token that puts the runner in a vehicle.
kind: 'token'— Always'token': what tells this item from the other kinds in a chunk.at: number— Where along the chunk.y: number— Its height.vehicle: string— The vehicle, by name in the run'svehicles.
JetpackView
interface JetpackView
What is where, for a presenter.
runner: JetpackRunnerState & { height: number; width: number; speed: number; alive: boolean }— The runner: its state, its body's size, and the speed.height: number— The corridor's height.zappers: JetpackZapperView[]— Every zapper in the loaded chunks, with its ends where its spin and slide have put them now.lasers: JetpackLaserView[]— Lasers now warning or firing.missiles: JetpackMissileView[]— Missiles now warning or flying.coins: JetpackThingView[]— Coins in the loaded chunks that have not been picked up.tokens: JetpackThingView[]— Vehicle tokens in the loaded chunks that have not been picked up.
JetpackZapper
interface JetpackZapper
A zapper: a deadly bar between two posts, standing, spinning or sliding up and down.
kind: 'zapper'— Always'zapper': what tells this item from the other kinds in a chunk.at: number— Where its middle is along the chunk.y: number— The height of its middle.length: number— Its length, post to post.angle?: number— Its angle, radians: 0 is level, π/2 upright. Default 0.spin?: number— Spin, radians a second. Default 0.sway?: number— Slide up and down this far either way. Default 0.period?: number— The seconds one slide up and down takes. Default 2.
JetpackZapperView
interface JetpackZapperView
A zapper, as drawn: its two ends.
id: string— Stable while the zapper is in the corridor: its chunk's index, a colon, then its place in the chunk's items.x1: number— One end's distance along the corridor, in world units.y1: number— That end's height above the floor, in world units.x2: number— The other end's distance along the corridor, in world units.y2: number— The other end's height above the floor, in world units.


