The pack
swipeCut
function swipeCut():Pack<{swipeCut:typeof kit}>
Install the public rules and seeded generator, independently of rendering.
Helpers
createSwipeCut
const createSwipeCut = (config: SwipeConfig)=> …
Creates a round from config. Throws if the target count, gravity, floor, misses, combo window, goal or any target value is out of range.
generateSwipeCut
function generateSwipeCut(o: SwipeOptions = {}): SwipeLevel
Generates a seeded level and certifies it by replaying a scripted safe performance; tries up to 40 candidates. Throws if an option is out of range or no candidate certifies.
Classes
SwipeCut
class SwipeCut
A swipe-cutting round: ballistic targets, swept strokes, combos, fragments, hints and undo by stroke. Rules only; it draws nothing.
readonly config: SwipeConfig— A validated copy of the configuration. The constructor throws if any value is out of range.constructor(c: SwipeConfig)get state()— A copy of the current state.get lost()— Whether the round is lost: a bomb was cut, too many fruit were missed, every fruit is resolved with the score under the goal (not in an endless round), or the time limit ran out with the score under the goal.get solved()— Whether the round is won: not lost, no stroke in progress, and the score at or above the goal once the time limit has run out or (not in an endless round) every fruit has been cut or missed.position(target: SwipeTarget, time = this.data.time): Point— Where a target is at a round time (default now), in the gameplay plane, from its launch and the config's gravity.active(time = this.data.time)— The targets in flight at a round time (default now): launched, not yet cut, missed or exploded, and not below the floor.step(dt: number)— Advances the round bydtseconds, 0 to 0.1 (throws outside that), marking fruit that fell past the floor as missed and judging the end of the round. Does nothing once the round is lost or solved.addTargets(targets: readonly SwipeTarget[]): number— Append targets to the round, for endless waves: ids must be new, and spawn times are round times, so launch them afterstate.time. A round that had run out of fruit becomes live again. Returns the new number of targets. Throws on a value out of range, a repeated id or more than 10000 targets in all.beginStroke(point: Point)— Starts a stroke at a point, ending any stroke in progress and recording an undo point; returns false if the round is over. Throws if a coordinate is outside plus or minus 30.strokeTo(to: Point)— Sweeps the stroke to a point, allowing for target movement since the last sample, and returns the ids hit; a bomb ends the round. Returns an empty list with no stroke in progress or for a move under 0.025. Throws if a coordinate is outside plus or minus 30.endStroke()— Ends the stroke in progress, scoring its combo bonus.fragments()— The two halves of each fruit cut in the last 3 seconds, for drawing: id<target>:<side>, the target'sfruitandradius,side-1 or 1,timein seconds since the cut and apositionthrown apart from the cut point under gravity. They never affect play.hint()— Fruit in flight that can be cut without a bomb nearby (more than 0.45 plane units beyond a bomb's radius), each{ id, point }with its current position, sorted left to right; empty when there is none.undo()— Restores the state from before the latest stroke began; false when there is nothing to undo.redo()— Replays an undone stroke point; false when there is nothing to redo.reset()— Returns to the start of the round and clears the undo history.
Types
SwipeConfig
interface SwipeConfig
An authored round: the targets and the rules that judge them.
targets: SwipeTarget[]— Every target of the round, 1 to 10000, with unique ids;addTargetsappends more during play up to the same bound. Each step and stroke scans every target, so the cost grows with the count.gravity: number— Downward acceleration in plane units per second squared, 1 to 40.floor: number— The y below which a falling target is out of play, -20 to 0.misses: number— Fruit that may be missed before the round is lost, a whole number 0 to 20; one more loses.comboWindow: number— Seconds, 0.1 to 3, over which cuts in one stroke count towards a single combo.goal: number— Score needed to win, a whole number 1 to 1000000: judged once every fruit has been cut or missed, or when the time limit runs out.endless?: boolean— An endless round (Fruit Ninja's classic mode): it never ends by running out of fruit, only by a bomb, too many misses or the time limit, and the game keeps it fed withaddTargets. Default false.timeLimit?: number— A timed round (Fruit Ninja's arcade mode): seconds, 0.1 to 3600, after which the round is over, won if the score reachedgoaland lost otherwise, whatever fruit is still flying. Default none.scoring?: SwipeScoring— Points for cuts and combos; omitted fields score as before: 10 a fruit, plus 5 a fruit in a combo of three or more.
SwipeCutApi
type SwipeCutApi=typeof kit
Public generator and rule constructors exposed on composed games.
SwipeGesture
interface SwipeGesture
One scripted stroke of a certificate, performed at its start time.
time: number— Round time in seconds at which the stroke is performed.points: Point[]— The pointer path in the gameplay plane: the stroke begins at the first point and sweeps through the rest.
SwipeLevel
interface SwipeLevel
A generated level with its replay-verified certificate and measurements.
seed: number— The seed the level was generated from.difficulty: Difficulty— The difficulty used.config: SwipeConfig— The playable round.parameters: Required<SwipeOptions>— Every option as resolved, defaults filled in; passing it back to the generator reproduces this level.solution: SwipeGesture[]— Scripted strokes, in time order, that replay to a win without hitting a bomb; one winning performance, not the only one.metrics: { /** The opening wave's layout family, such as 'ring'. */ family: string; /** One entry per wave: its layout, group sizes and mirroring, as \recipe:sizes:mirror`. / encounters: string[]; /* Fruit in the round. / fruits: number; /* Bombs in the round. / bombs: number; /* Waves in the round. / waves: number; /* The closest, in plane units, a certifying stroke passes to a bomb's edge. / minimumClearance: number; /* Round time, in seconds, of the last certifying stroke. / duration: number; /* The encounters as JSON, used to tell levels apart. */ structure: string; }` — Measurements of the generated level.
SwipeOptions
interface SwipeOptions
Level controls for generateSwipeCut; every field has a default and an explicit range.
seed?: number— Unsigned 32-bit integer, 0 allowed. Default 1.difficulty?: Difficulty—'easy','medium','hard'or'very-hard'. Default'medium'.waves?: number— Waves of targets, 2 to 20. Default 6, 9, 12 or 15 by difficulty, plus the seed modulo 3.fruits?: number— Most fruit in a wave, 2 to 6; a wave may hold fewer. Default 3, 4, 5 or 6 by difficulty.bombs?: number— Bombs in each wave, 0 to 3. Default 0, 1, 2 or 3 by difficulty.flightTime?: number— Flight timescale in seconds, 1.2 to 3: fruit are planned to be cut about half of this after launch, so smaller values give faster waves. Default 2.3, 2.05, 1.8 or 1.55 by difficulty.pattern?: 'auto' | 'fan' | 'crossing' | 'lanes' | 'ladder' | 'split' | 'ring' | 'cascade'— How each wave is laid out:'auto'mixes the families per wave,'lanes'is the ladder layout, or name one of'fan','crossing','ladder','split','ring','cascade'. Default'auto'.misses?: number— Fruit that may be missed before the round is lost (the lives), 0 to 20. Default 3, 2, 1 or 0 by difficulty.
SwipeScoring
interface SwipeScoring
Points for cuts and combos; every field is optional and defaults as described.
fruit?: number— Points for each fruit cut, 0 to 1000; default 10.comboMin?: number— Fruit one combo window must cut to earn the combo bonus, a whole number from 2 to 20; default 3.comboBonus?: number— Extra points per fruit of a combo that reachescomboMin, 0 to 1000; default 5.
SwipeState
interface SwipeState
The round's progress: clock, results, score, the stroke in progress and the cuts made.
time: number— Seconds since the round started.cut: string[]— Ids of the fruit cut so far, in order.missed: string[]— Ids of the fruit that fell below the floor uncut.bombs: string[]— Ids of the bombs that were cut; any one loses the round.score: number— Points so far: by default 10 for each fruit, plus 5 more per fruit in a combo of three or more;SwipeConfig.scoringchanges the amounts.strokes: number— Strokes begun so far.bestCombo: number— Most fruit cut in one combo window so far.lastCombo: number— Fruit cut in the most recently closed combo window.lost: boolean— Whether the round is lost: a bomb was cut, too many fruit were missed, every fruit is resolved with the score under the goal (not in an endless round), or the time limit ran out with the score under the goal.stroke: { from: Point; time: number; started: number; ids: string[]; } | null— The stroke in progress, or null:fromis its last sampled point,timethe round time of that sample,startedwhen the current combo window opened andidsthe fruit cut in it.cuts: { id: string; time: number; direction: Point; }[]— Every cut made: the target id, the round time and the swipe's direction vector, which drives the fragments.
SwipeTarget
interface SwipeTarget
A fruit or bomb thrown on a ballistic arc in the gameplay plane; it flies under the config's gravity from origin at spawn.
id: string— Unique target name, used by cuts, misses, bomb hits and fragments.kind: 'fruit' | 'bomb'—'fruit'scores when cut;'bomb'loses the round when cut.fruit: number— Fruit variety index for the presenter to choose a look from; generated levels use 0 to 4.spawn: number— Seconds after the round starts at which it is launched, 0 to 300.origin: Point— Launch position in the gameplay plane, each coordinate within plus or minus 20.velocity: Point— Launch velocity in plane units per second, each component within plus or minus 40.radius: number— Hit radius in plane units, 0.1 to 1.


