The pack
crossyRoad
function crossyRoad(): Pack<{ crossyRoad: CrossyRoadApi }>
The crossy-road pack: game.crossyRoad, Crossy Road's rules as a row grammar on lane-control. No options.
Helpers
createCrossyAutopilot
function createCrossyAutopilot(game: CrossyRoadGame, options: CrossyAutopilotOptions = {}): CrossyAutopilot
A crossing's autopilot. It only reads game; give its hop to game.hop.
createCrossyRoad
function createCrossyRoad(options: CrossyOptions = {}): CrossyRoadGame
Start a crossing. Throws, with every fault, on options it refuses.
crossyRows
const crossyRows: Record<string, CrossyRowKind>
The built-in row kinds: Crossy Road's grass, roads, rivers and railways.
crossySegments
const crossySegments: CrossySegment[]
The built-in segments: a start, then grass, roads, highways, rivers, ponds and railways, harder further on.
validateCrossyRoad
function validateCrossyRoad(options: CrossyOptions = {}): string[]
Check a crossing's options. Empty when it can be played.
Types
CrossyAutopilot
interface CrossyAutopilot
A player that picks the next hop.
next(): CrossyMove | null— The hop to make now, or null to wait. Call it before each step.
CrossyAutopilotOptions
interface CrossyAutopilotOptions
How the autopilot plans.
search?: number— Seconds the route search looks ahead at most. Default 7.tick?: number— Seconds between steps of the search. Default 0.1.breadth?: number— States the search keeps per step at most. Default 400.
CrossyEagle
interface CrossyEagle
The eagle: it takes a chicken that waits too long or falls behind the screen.
idle: number— Seconds without a step forward before it comes. Default 8.creep: number— Rows the screen creeps forward a second. Default 0.25.behind: number— Rows behind the screen's line that it comes at. Default 3.
CrossyEvent
type CrossyEvent = | { kind: 'hop'; move: CrossyMove } | { kind: 'bump'; move: CrossyMove } | { kind: 'land'; row: number; on: 'ground' | 'log' | 'pad' } | { kind: 'coin'; row: number; total: number } | { kind: 'forward'; row: number } | { kind: 'bell'; row: number } | { kind: 'over'; cause: 'car' | 'train' | 'water' | 'drift' | 'eagle' }
Something that happened.
CrossyGrass
interface CrossyGrass
Grass: trees in the way, coins to take.
kind: 'grass'— Row type tag; always'grass'.trees?: number— Chance a cell has a tree, 0 to 1. A path through is always kept clear. Default 0.2.coins?: number— Chance the row has a coin. Default 0.15.name?: string— Presenter name.
CrossyMove
type CrossyMove = 'up' | 'down' | 'left' | 'right'
A hop.
CrossyMover
interface CrossyMover
A moving thing, as drawn: x is its left edge in playable columns (it may be off either side).
id: string— Unique within a view: the row index and the piece's lane id, such as'12:p0'; a train is'12:train'.row: number— Index of the row it travels on.kind: string— Presenter name from its template, such as'car','truck'or'log';'train'for a train.x: number— Left edge in playable columns, 0 at the left playable column; below 0 or at leastwidthwhile out in the overhang.length: number— Length in cells.
CrossyOptions
interface CrossyOptions
A crossing's options.
seed?: number— The seed. Default 1.width?: number— Playable columns. Default 9.overhang?: number— Columns off each side where traffic and logs run on, out of reach. Default 4.rows?: Record<string, CrossyRowKind>— The row kinds, by name. DefaultcrossyRows.segments?: CrossySegment[]— The segments. DefaultcrossySegments.opening?: string[]— Segments played first. Default['start']with the built-in segments.hopTime?: number— Seconds a hop takes. Default 0.14.radius?: number— The chicken's half width, in cells. Default 0.3.eagle?: Partial<CrossyEagle>— The eagle.pace?: number— Speed factor for every moving row: a harder game. Default 1.
CrossyPiece
interface CrossyPiece
A moving piece's template: what it is and how long, in cells. Several lengths pick by seed.
kind: string— Presenter name: 'car', 'truck', 'log'.length: CrossyRange— Length in cells.
CrossyRail
interface CrossyRail
A railway: lights flash, then a train goes through.
kind: 'rail'— Row type tag; always'rail'.period: CrossyRange— Seconds between trains.warning?: number— Seconds the lights flash before a train. Default 1.6.length?: number— The train's length in cells. Default 14.speed?: number— Its speed, cells a second. Default 32.name?: string— Presenter name.
CrossyRange
type CrossyRange = number | [number, number]
A range picked by seed: one value, or [min, max].
CrossyRiver
interface CrossyRiver
A river: the only footing is the logs (drifting) or lily pads (still).
kind: 'river'— Row type tag; always'river'.speed?: CrossyRange— Cells a second for logs; direction picked by seed. Ignored withpads.count: CrossyRange— How many logs, or lily pads.pieces?: CrossyPiece[]— Log templates. Ignored withpads.pads?: boolean— Still lily pads, one cell each, instead of logs.gap?: number— Least water between logs. Default 1.2.name?: string— Presenter name.
CrossyRoad
interface CrossyRoad
A road: traffic that kills.
kind: 'road'— Row type tag; always'road'.speed: CrossyRange— Cells a second; direction picked by seed.count: CrossyRange— How many vehicles.pieces: CrossyPiece[]— Vehicle templates, used in turn.gap?: number— Least clear cells between vehicles. Default 1.5.coins?: number— Chance the row has a coin. Default 0.1.name?: string— Presenter name.
CrossyRoadApi
interface CrossyRoadApi
What the crossy-road pack adds to a game: game.crossyRoad.
create: typeof createCrossyRoad— Start a crossing.validate: typeof validateCrossyRoad— Check a crossing's options; empty when it can be played.rows: typeof crossyRows— The built-in row kinds.segments: typeof crossySegments— The built-in segments.autopilot: typeof createCrossyAutopilot— A player that looks ahead, for an attract mode or a test.
CrossyRoadGame
interface CrossyRoadGame
A crossing.
readonly state: CrossyState— Where the chicken is.readonly options: Readonly<{ width: number; overhang: number; hopTime: number; radius: number; eagle: CrossyEagle; pace: number }>— The options, defaults filled in.hop(move: CrossyMove): boolean— A hop, if the way is open and the chicken is not mid-hop; returns whether it went.step(dt: number): void— Advancedtseconds, in fixed steps of 1/120 s.row(index: number): CrossyRow— The row at an index (generated on demand).view(behind?: number, ahead?: number): CrossyView— What is where.drain(): CrossyEvent[]— Events since the last call.snapshot(): CrossySave— The run as plain JSON.restore(save: CrossySave): void— Pick up a saved run made with the same options.clone(): CrossyRoadGame— A separate run with the same options at the same point.
CrossyRow
interface CrossyRow
A row as laid: its kind and what is on it.
index: number— Its index: 0 is the start.name: string— Its kind's name.kind: CrossyRowKind['kind']— Its kind.trees: number[]— Trees, by column (grass).path: number— A column the generator keeps open: on grass no tree stands on it or on the path's column in the rows either side, and a pond has a pad on it and on the column of the row before.coin: number | null— A coin's column, or null.lane: LaneDefinition | null— Its moving lane (road and river logs): lane-control's definition, positions at time 0, in lane cells.pads: number[]— Lily pads, by column (river with pads).rail: { period: number; offset: number; warning: number; length: number; speed: number } | null— Railway timing: seconds between trains, and where in that it starts.
CrossyRowKind
type CrossyRowKind = CrossyGrass | CrossyRoad | CrossyRiver | CrossyRail
A kind of row.
CrossySave
interface CrossySave
A crossing saved as plain JSON. The rows are not in it: they follow from the seed.
seed: number— The seed of the crossing;restorerefuses a save with a different seed.width: number— Playable columns of the crossing;restorerefuses a save with a different width.state: CrossyState— The chicken and run state when the save was made.taken: number[]— Indices of the rows whose coin has already been picked up.
CrossySegment
interface CrossySegment
A run of rows: row kinds by name, each repeated count times.
id: string— Its name.rows: (string | { row: string; count: CrossyRange })[]— The rows, in order.weight?: number— Likelihood against the others. Default 1; 0 is foropeningonly.from?: number— The first row it may start at. Default 0.until?: number— The last row it may start at. Default no limit.follows?: string[]— May only come straight after one of these segments.never?: string[]— Never comes straight after one of these.
CrossyState
interface CrossyState
Where the chicken is and how the run stands.
x: number— Across, in columns (0 is the left edge's column); continuous while on a log.row: number— Its row; between two rows while hopping.furthest: number— The furthest row reached: the score.coins: number— Coins.time: number— Seconds run.idle: number— Seconds since the last step forward.screen: number— The screen's line, in rows: it creeps forward and follows the chicken.hop: { fromX: number; fromRow: number; toX: number; toRow: number; t: number; move: CrossyMove } | null— The hop in the air: from, to, and how far through.facing: CrossyMove— The way it faces.alive: boolean— False once the run is over.cause: 'car' | 'train' | 'water' | 'drift' | 'eagle' | null— Why it ended.
CrossyView
interface CrossyView
What is where, for a presenter.
chicken: CrossyState— The chicken.rows: CrossyRow[]— The rows frombehindtoahead.movers: CrossyMover[]— Cars, trucks and logs where they are now.trains: CrossyMover[]— Trains where they are now, and railways whose lights flash.warnings: number[]— Rows whose lights are flashing.width: number— Playable columns, and the overhang either side.overhang: number— Columns of overhang either side of the playable width, where movers run out of reach.


