Reference · Controllers and canvas player
Controllertype
One level of one game, played.
Import it
import type { Controller } from "@johnmorrisdotca/karakuri/play";
Also exported from: @johnmorrisdotca/karakuri
Definition
interface Controller {
readonly width: number;
readonly height: number;
readonly gesture: "drag" | "tap";
readonly status: Status;
readonly result: Say | null;
readonly info: Say;
readonly animating: boolean;
pointerDown(p: Point, id: number): void;
pointerMove(p: Point, id: number): void;
pointerUp(p: Point, id: number): void;
pointerCancel(id: number): void;
tick(): void;
draw(g: CanvasRenderingContext2D, theme: Theme): void;
restart(): void;
snapshot(): unknown;
}
Members
| Name | Type | Description |
|---|---|---|
width | number | The size of the play area, in the game's units. The player scales it to the box it is given. |
height | number | |
gesture | "drag" | "tap" |
|
status | Status | |
result | Say | null | Why a level was won or lost, in words, once it has been. |
info | Say | The line shown above the board. |
animating | boolean | Whether time is passing in the game (physics running, an animation playing), so that the player keeps stepping and drawing. |
pointerDown | (p: Point, id: number): void | |
pointerMove | (p: Point, id: number): void | |
pointerUp | (p: Point, id: number): void | |
pointerCancel | (id: number): void | |
tick | (): void | Advances the game by one fixed step (a sixtieth of a second). |
draw | (g: CanvasRenderingContext2D, theme: Theme): void | |
restart | (): void | Starts the same level again. |
snapshot | (): unknown | Plain data for a test or a page to read what is going on. |
Examples
import { createController } from "@johnmorrisdotca/karakuri/play";
import type { Controller } from "@johnmorrisdotca/karakuri/play";
const controller=createController("tube-sort",1);
const value: Controller = controller;
console.log(value);{
width: 360,
height: 420,
gesture: 'tap',
status: [Getter],
result: [Getter],
info: [Getter],
animating: [Getter],
pointerDown: [Function: pointerDown],
pointerMove: [Function: pointerMove],
pointerUp: [Function: pointerUp],
pointerCancel: [Function: pointerCancel],
tick: [Function: tick],
draw: [Function: draw],
restart: [Function: restart],
snapshot: [Function: snapshot]
}What it prints (run when this page was built)