The pack
ninjaRope2d
function ninjaRope2d(): Pack<{ ninjaRope: NinjaRopeApi }>
The ninja-rope-2d pack: game.ninjaRope, rope-swinging courses.
Helpers
createRopeCourse
function createRopeCourse(course: RopeCourse): CourseGame
Make a game of a course. Throws, listing every problem, on a course validateRopeCourse refuses.
validateRopeCourse
function validateRopeCourse(course: RopeCourse): string[]
Check a course and say what is wrong with it, as plain sentences; empty when it can be played.
Constants
ropeCourses
const ropeCourses: { readonly ninja: readonly RopeCourse[]; readonly grapple: readonly RopeCourse[] }
The built-in courses, by rope.
Types
CourseControls
interface CourseControls
What the player is doing, held from step to step.
move?: number— Walk or push: -1 left to 1 right.reel?: number— Reel in (1) or pay out (-1).
CourseEvent
type CourseEvent = | { kind: 'gate'; gate: number } | { kind: 'fall'; cause: 'pit' | 'hazard' } | { kind: 'jump' } | { kind: 'won'; time: number; falls: number; stars: number } | { kind: 'rope'; event: RopeSwingEvent }
What happened, for the presenter.
CourseGame
interface CourseGame
A game of one course.
readonly course: Readonly<RopeCourse>— The course (a copy).readonly rope: Readonly<Omit<RopeSwingOptions, 'surfaces'>>— The rope's options, the preset filled in.readonly state: Readonly<CourseState>— The state, live.hold(controls: CourseControls): void— Set the held controls.jump(): boolean— Jump, when standing on something.fire(target: SwingPoint): boolean— Fire the rope at a point: whether it hooked something.release(): void— Let go of the rope.step(dt: number): void— Advance bydtseconds.stars(): number— Stars for the time taken: 3 within par, 2 within half again, else 1.drain(): CourseEvent[]— What happened since the last drain, oldest first.view(): CourseView— Everything to draw.restart(): void— Start the course again.snapshot(): CourseSave— The game as plain JSON: its moves, replayed on restore.restore(save: CourseSave): void— Resume a snapshot of this course. Throws on another course's, and leaves the game as it was.
CourseGate
interface CourseGate
A gate: pass within its radius, in order. A passed gate is where a fall sends the runner back to.
x: number— Where it is, across.y: number— Where it is, down.radius?: number— How near counts. Default 50.
CourseMove
type CourseMove = | { kind: 'advance'; seconds: number } | { kind: 'hold'; move: number; reel: number } | { kind: 'jump' } | { kind: 'fire'; x: number; y: number } | { kind: 'release' }
A move: time passing, the held controls changed, a jump, the rope fired at a point, or let go.
CourseRunner
interface CourseRunner
The runner.
width?: number— Its width. Default 18.height?: number— Its height. Default 26.walk?: number— How fast it walks. Default 170.jump?: number— How hard it jumps: the speed it leaves the ground at. Default 430.air?: number— How hard it pushes while in the air or on the rope, units per second squared. Default 420.
CourseSave
interface CourseSave
A saved game.
format: 'phaser-ae-rope-course'— Always'phaser-ae-rope-course'.version: 1— The save format's version, 1.course: string— The course's id ('' for one without).history: ReturnType<History<unknown, CourseMove>['snapshot']>— The moves, as the kernel's history saves them.
CourseState
interface CourseState
The game's state.
phase: 'playing' | 'won'—'playing'until the goal is reached ('won').time: number— Seconds played.falls: number— Times the runner has fallen or touched a hazard.gate: number— How many gates are passed.shots: number— Ropes fired.grounded: boolean— Whether the runner stands on something.
CourseSurface
interface CourseSurface
A course surface: a box, solid unless it is a hazard.
id: string— Its id.x: number— Its centre, across.y: number— Its centre, down.width: number— Its width.height: number— Its height.hookable?: boolean— Whether the rope can hook it. Default true.hazard?: boolean— A hazard: touching it sends the runner back. It is not solid, and the rope cannot hook it.
CourseView
interface CourseView
Everything a presenter draws.
runner: { x: number; y: number; vx: number; vy: number; width: number; height: number; facing: 1 | -1; grounded: boolean }— The runner: where it is, how fast, which way it faces.rope: SwingPoint[]— The rope's line, hook first; empty when it is not out.taut: boolean— Whether the rope is pulled straight.surfaces: CourseSurface[]— The surfaces, as the course gave them.gates: { x: number; y: number; radius: number; passed: boolean }[]— Each gate, and whether it is passed.goal: { x: number; y: number; radius: number }— The goal.
NinjaRopeApi
interface NinjaRopeApi
What the ninja-rope-2d pack adds to a game: game.ninjaRope.
create: typeof createRopeCourse— Make a game of a course.validate: typeof validateRopeCourse— Check a course; empty when it can be played.courses: typeof ropeCourses— The built-in courses.
RopeCourse
interface RopeCourse
A course.
id?: string— Its id, which saves carry.name?: string— A name to show.width: number— The course's width.height: number— The course's height.gravity?: number— Gravity, units per second squared, down. Default 900.surfaces: CourseSurface[]— The surfaces.start: SwingPoint— Where the runner starts (its centre).goal: CourseGate— Where it must get to, after every gate.gates?: CourseGate[]— Gates to pass, in order.fall?: number— Below this the runner has fallen. Default the course's height.rope?: keyof typeof ropeSwingPresets | Omit<RopeSwingOptions, 'surfaces'>— The rope: a preset by name, or options. Default'ninja'.runner?: CourseRunner— The runner.par?: number— Seconds for three stars. Default none: every finish is three stars.


