kaplay
Version:
KAPLAY is a JavaScript & TypeScript game library that helps you make games fast and fun! (formerly known as Kaboom.js)
2,272 lines (2,271 loc) • 236 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
/**
* A button binding.
*
* @group Button Bindings
*/
export type ButtonBinding = {
keyboard?: Key | Key[];
keyboardCode?: string | string[];
gamepad?: KGamepadButton | KGamepadButton[];
mouse?: MouseButton | MouseButton[];
};
/**
* A buttons definition for an action (jump, walk-left, run).
*
* @group Button Bindings
*/
export type ButtonsDef = Record<string, ButtonBinding>;
/**
* A button binding device
*
* @group Button Bindings
*/
export type ButtonBindingDevice = "keyboard" | "gamepad" | "mouse";
export type GfxCtx = ReturnType<typeof initGfx>;
export declare class Texture {
ctx: GfxCtx;
src: null | ImageSource;
glTex: WebGLTexture;
width: number;
height: number;
constructor(ctx: GfxCtx, w: number, h: number, opt?: TextureOpt);
static fromImage(ctx: GfxCtx, img: ImageSource, opt?: TextureOpt): Texture;
update(img: ImageSource, x?: number, y?: number): void;
bind(): void;
unbind(): void;
/** Frees up texture memory. Call this once the texture is no longer being used to avoid memory leaks. */
free(): void;
}
/**
* @group GFX
*/
export declare class FrameBuffer {
ctx: GfxCtx;
tex: Texture;
glFramebuffer: WebGLFramebuffer;
glRenderbuffer: WebGLRenderbuffer;
constructor(ctx: GfxCtx, w: number, h: number, opt?: TextureOpt);
get width(): number;
get height(): number;
toImageData(): ImageData;
toDataURL(): string;
clear(): void;
draw(action: () => void): void;
bind(): void;
unbind(): void;
free(): void;
}
export type VertexFormat = {
name: string;
size: number;
}[];
export declare class BatchRenderer {
ctx: GfxCtx;
glVBuf: WebGLBuffer;
glIBuf: WebGLBuffer;
vqueue: number[];
iqueue: number[];
stride: number;
maxVertices: number;
maxIndices: number;
vertexFormat: VertexFormat;
numDraws: number;
curPrimitive: GLenum | null;
curTex: Texture | null;
curShader: Shader | null;
curUniform: Uniform;
constructor(ctx: GfxCtx, format: VertexFormat, maxVertices: number, maxIndices: number);
push(primitive: GLenum, verts: number[], indices: number[], shader: Shader, tex?: Texture | null, uniform?: Uniform): void;
flush(): void;
free(): void;
}
export declare class Mesh {
ctx: GfxCtx;
glVBuf: WebGLBuffer;
glIBuf: WebGLBuffer;
vertexFormat: VertexFormat;
count: number;
constructor(ctx: GfxCtx, format: VertexFormat, verts: number[], indices: number[]);
draw(primitive?: GLenum): void;
free(): void;
}
declare function initGfx(gl: WebGLRenderingContext, opts?: {
texFilter?: TexFilter;
}): {
gl: WebGLRenderingContext;
opts: {
texFilter?: TexFilter;
};
onDestroy: (action: () => unknown) => void;
destroy: () => void;
pushTexture2D: (item: WebGLTexture) => void;
popTexture2D: () => void;
pushArrayBuffer: (item: WebGLBuffer) => void;
popArrayBuffer: () => void;
pushElementArrayBuffer: (item: WebGLBuffer) => void;
popElementArrayBuffer: () => void;
pushFramebuffer: (item: WebGLFramebuffer) => void;
popFramebuffer: () => void;
pushRenderbuffer: (item: WebGLRenderbuffer) => void;
popRenderbuffer: () => void;
pushViewport: (item: {
x: number;
y: number;
w: number;
h: number;
}) => void;
popViewport: () => void;
pushProgram: (item: WebGLProgram) => void;
popProgram: () => void;
setVertexFormat: (fmt: VertexFormat) => void;
};
export type RGBValue = [
number,
number,
number
];
export type RGBAValue = [
number,
number,
number,
number
];
/**
* 0-255 RGBA color.
*
* @group Math
*/
export declare class Color {
/** Red (0-255. */
r: number;
/** Green (0-255). */
g: number;
/** Blue (0-255). */
b: number;
constructor(r: number, g: number, b: number);
static fromArray(arr: number[]): Color;
/**
* Create color from hex string or literal.
*
* @example
* ```js
* Color.fromHex(0xfcef8d)
* Color.fromHex("#5ba675")
* Color.fromHex("d46eb3")
* ```
*
* @since v3000.0
*/
static fromHex(hex: string | number): Color;
static fromHSL(h: number, s: number, l: number): Color;
static RED: Color;
static GREEN: Color;
static BLUE: Color;
static YELLOW: Color;
static MAGENTA: Color;
static CYAN: Color;
static WHITE: Color;
static BLACK: Color;
clone(): Color;
/** Lighten the color (adds RGB by n). */
lighten(a: number): Color;
/** Darkens the color (subtracts RGB by n). */
darken(a: number): Color;
invert(): Color;
mult(other: Color): Color;
/**
* Linear interpolate to a destination color.
*
* @since v3000.0
*/
lerp(dest: Color, t: number): Color;
/**
* Convert color into HSL format.
*
* @since v3001.0
*/
toHSL(): [
number,
number,
number
];
eq(other: Color): boolean;
toString(): string;
/**
* Return the hex string of color.
*
* @since v3000.0
*/
toHex(): string;
/**
* Return the color converted to an array.
*
* @since v3001.0
*/
toArray(): Array<number>;
}
export type ColorArgs = [
Color
]
/**
* rgb(new Color(255, 255, 255), 1)
*
* This is only used to parse directly the color of background. This
* syntax shouldn't be used to set opacity. Use `opacity()` comp instead.
*/
| [
Color,
number
] | RGBValue
/**
* rgb(255, 255, 255, 1)
*
* This is only used to parse directly the color of background. This
* syntax shouldn't be used to set opacity. Use `opacity()` comp instead.
*/
| RGBAValue | [
string
] | [
number[]
] | [
];
/**
* Possible arguments for a Vec2.
*
* @group Math
*/
export type Vec2Args = [
number,
number
] | [
number
] | [
Vec2
] | [
number | Vec2
] | [
];
/**
* A 2D vector.
*
* @group Math
*/
export declare class Vec2 {
/** The x coordinate */
x: number;
/** The y coordinate */
y: number;
constructor(x?: number, y?: number);
/** Create a new Vec2 from an angle in degrees */
static fromAngle(deg: number): Vec2;
/** Create a new Vec2 from an array */
static fromArray(arr: Array<number>): Vec2;
/** An empty vector. (0, 0) */
static ZERO: Vec2;
/** A vector with both components of 1. (1, 1) */
static ONE: Vec2;
/** A vector signaling to the left. (-1, 0) */
static LEFT: Vec2;
/** A vector signaling to the right. (1, 0) */
static RIGHT: Vec2;
/** A vector signaling up. (0, -1) */
static UP: Vec2;
/** A vector signaling down. (0, 1) */
static DOWN: Vec2;
/** Clone the vector */
clone(): Vec2;
/** Returns the addition with another vector. */
add(...args: Vec2Args): Vec2;
/** Returns the subtraction with another vector. */
sub(...args: Vec2Args): Vec2;
/** Scale by another vector. or a single number */
scale(...args: Vec2Args): Vec2;
/** Get distance between another vector */
dist(...args: Vec2Args): number;
/** Get squared distance between another vector */
sdist(...args: Vec2Args): number;
/**
* Calculates the squared distance between the vectors
* @param v The vector
* @param other The other vector
* @returns The distance between the vectors
*/
static sdist(v: Vec2, other: Vec2): number;
/**
* Get length of the vector
*
* @since v3000.0
*/
len(): number;
/**
* Get squared length of the vector
*
* @since v3000.0
*/
slen(): number;
/**
* Get the unit vector (length of 1).
*/
unit(): Vec2;
/**
* Get the perpendicular vector.
*/
normal(): Vec2;
/**
* Get the reflection of a vector with a normal.
*
* @since v3000.0
*/
reflect(normal: Vec2): Vec2;
/**
* Get the projection of a vector onto another vector.
*
* @since v3000.0
*/
project(on: Vec2): Vec2;
/**
* Get the rejection of a vector onto another vector.
*
* @since v3000.0
*/
reject(on: Vec2): Vec2;
/**
* Get the dot product with another vector.
*/
dot(p2: Vec2): number;
/**
* Get the dot product between 2 vectors.
*
* @since v3000.0
*/
static dot(v: Vec2, other: Vec2): number;
/**
* Get the cross product with another vector.
*
* @since v3000.0
*/
cross(p2: Vec2): number;
/**
* Get the cross product between 2 vectors.
*
* @since v3000.0
*/
static cross(v: Vec2, other: Vec2): number;
/**
* Get the angle of the vector in degrees.
*/
angle(...args: Vec2Args): number;
/**
* Get the angle between this vector and another vector.
*
* @since v3000.0
*/
angleBetween(...args: Vec2Args): number;
/**
* Linear interpolate to a destination vector (for positions).
*/
lerp(dest: Vec2, t: number): Vec2;
/**
* Spherical linear interpolate to a destination vector (for rotations).
*
* @since v3000.0
*/
slerp(dest: Vec2, t: number): Vec2;
/**
* If the vector (x, y) is zero.
*
* @since v3000.0
*/
isZero(): boolean;
/**
* To n precision floating point.
*/
toFixed(n: number): Vec2;
/**
* Multiply by a Mat4.
*
* @since v3000.0
*/
transform(m: Mat4): Vec2;
/**
* See if one vector is equal to another.
*
* @since v3000.0
*/
eq(other: Vec2): boolean;
/** Converts the vector to a {@link Rect `Rect()`} with the vector as the origin.
* @since v3000.0.
*/
bbox(): Rect;
/** Converts the vector to a readable string. */
toString(): string;
/** Converts the vector to an array.
* @since v3001.0
*/
toArray(): Array<number>;
}
/**
* @group Math
*/
export declare class Quad {
x: number;
y: number;
w: number;
h: number;
constructor(x: number, y: number, w: number, h: number);
scale(other: Quad): Quad;
pos(): Vec2;
clone(): Quad;
eq(other: Quad): boolean;
toString(): string;
}
declare class Mat2 {
a: number;
b: number;
c: number;
d: number;
constructor(a: number, b: number, c: number, d: number);
mul(other: Mat2): Mat2;
transform(point: Vec2): Vec2;
get inverse(): Mat2;
get transpose(): Mat2;
get eigenvalues(): number[];
eigenvectors(e1: number, e2: number): number[][];
get det(): number;
get trace(): number;
static rotation(radians: number): Mat2;
static scale(x: number, y: number): Mat2;
}
/**
* @group Math
*/
export declare class Mat4 {
m: number[];
constructor(m?: number[]);
static translate(p: Vec2): Mat4;
static scale(s: Vec2): Mat4;
static rotateX(a: number): Mat4;
static rotateY(a: number): Mat4;
static rotateZ(a: number): Mat4;
translate(p: Vec2): this;
scale(p: Vec2): this;
rotate(a: number): Mat4;
mult(other: Mat4): Mat4;
multVec2(p: Vec2): Vec2;
getTranslation(): Vec2;
getScale(): Vec2;
getRotation(): number;
getSkew(): Vec2;
invert(): Mat4;
clone(): Mat4;
toString(): string;
}
/**
* @group Math
*/
export declare class RNG {
seed: number;
constructor(seed: number);
gen(): number;
genNumber(a: number, b: number): number;
genVec2(a: Vec2, b: Vec2): Vec2;
genColor(a: Color, b: Color): Color;
genAny<T = RNGValue>(...args: [
] | [
T
] | [
T,
T
]): T;
}
/**
* @group Math
*/
export type ShapeType = Point | Circle | Line | Rect | Polygon | Ellipse;
/**
* @group Math
*/
export type RaycastHit = {
fraction: number;
normal: Vec2;
point: Vec2;
gridPos?: Vec2;
object?: GameObj;
};
/**
* @group Math
*/
export type RaycastResult = RaycastHit | null;
export declare class Point {
pt: Vec2;
constructor(pt: Vec2);
transform(m: Mat4): Point;
bbox(): Rect;
area(): number;
clone(): Point;
collides(shape: ShapeType): boolean;
contains(point: Vec2): boolean;
raycast(origin: Vec2, direction: Vec2): RaycastResult;
random(): Vec2;
}
/**
* @group Math
*/
export declare class Line {
p1: Vec2;
p2: Vec2;
constructor(p1: Vec2, p2: Vec2);
transform(m: Mat4): Line;
bbox(): Rect;
area(): number;
clone(): Line;
collides(shape: ShapeType | Vec2): boolean;
contains(point: Vec2): boolean;
raycast(origin: Vec2, direction: Vec2): RaycastResult;
random(): Vec2;
}
/**
* @group Math
*/
export declare class Rect {
pos: Vec2;
width: number;
height: number;
constructor(pos: Vec2, width: number, height: number);
static fromPoints(p1: Vec2, p2: Vec2): Rect;
center(): Vec2;
points(): [
Vec2,
Vec2,
Vec2,
Vec2
];
transform(m: Mat4): Polygon;
bbox(): Rect;
area(): number;
clone(): Rect;
distToPoint(p: Vec2): number;
sdistToPoint(p: Vec2): number;
collides(shape: ShapeType | Vec2): boolean;
contains(point: Vec2): boolean;
raycast(origin: Vec2, direction: Vec2): RaycastResult;
random(): Vec2;
}
/**
* @group Math
*/
export declare class Circle {
center: Vec2;
radius: number;
constructor(center: Vec2, radius: number);
transform(tr: Mat4): Ellipse;
bbox(): Rect;
area(): number;
clone(): Circle;
collides(shape: ShapeType | Vec2): boolean;
contains(point: Vec2): boolean;
raycast(origin: Vec2, direction: Vec2): RaycastResult;
random(): Vec2;
}
/**
* @group Math
*/
export declare class Ellipse {
center: Vec2;
radiusX: number;
radiusY: number;
angle: number;
constructor(center: Vec2, rx: number, ry: number, degrees?: number);
static fromMat2(tr: Mat2): Ellipse;
toMat2(): Mat2;
transform(tr: Mat4): Ellipse;
bbox(): Rect;
area(): number;
clone(): Ellipse;
collides(shape: ShapeType): boolean;
contains(point: Vec2): boolean;
raycast(origin: Vec2, direction: Vec2): RaycastResult;
random(): Vec2;
}
/**
* @group Math
*/
export declare class Polygon {
pts: Vec2[];
constructor(pts: Vec2[]);
transform(m: Mat4): Polygon;
bbox(): Rect;
area(): number;
clone(): Polygon;
collides(shape: ShapeType | Vec2): boolean;
contains(point: Vec2): boolean;
raycast(origin: Vec2, direction: Vec2): RaycastResult;
random(): Vec2;
cut(a: Vec2, b: Vec2): [
Polygon | null,
Polygon | null
];
}
export type StepPosition = "jump-start" | "jump-end" | "jump-none" | "jump-both";
export type SatResult = {
normal: Vec2;
distance: number;
};
export type DrawCurveOpt = RenderProps & {
/**
* The amount of line segments to draw.
*/
segments?: number;
/**
* The width of the line.
*/
width?: number;
};
export type DrawBezierOpt = DrawCurveOpt & {
/**
* The first point.
*/
pt1: Vec2;
/**
* The the first control point.
*/
pt2: Vec2;
/**
* The the second control point.
*/
pt3: Vec2;
/**
* The second point.
*/
pt4: Vec2;
};
/**
* How the circle should look like.
*/
export type DrawCircleOpt = Omit<RenderProps, "angle"> & {
/**
* Radius of the circle.
*/
radius: number;
/**
* Starting angle.
*/
start?: number;
/**
* Ending angle.
*/
end?: number;
/**
* If fill the shape with color (set this to false if you only want an outline).
*/
fill?: boolean;
/**
* Use gradient instead of solid color.
*
* @since v3000.0
*/
gradient?: [
Color,
Color
];
/**
* Multiplier for circle vertices resolution (default 1)
*/
resolution?: number;
/**
* The anchor point, or the pivot point. Default to "topleft".
*/
anchor?: Anchor | Vec2;
};
export interface GfxFont {
tex: Texture;
map: Record<string, Quad>;
size: number;
}
export type BitmapFontData = GfxFont;
export interface LoadBitmapFontOpt {
chars?: string;
filter?: TexFilter;
outline?: number;
}
export declare class FontData {
fontface: FontFace;
filter: TexFilter;
outline: Outline | null;
size: number;
constructor(face: FontFace, opt?: LoadFontOpt);
}
/**
* How the text should look like.
*
* @group Draw
*/
export type DrawTextOpt = RenderProps & {
/**
* The text to render.
*/
text: string;
/**
* The name of font to use.
*/
font?: string | FontData | Asset<FontData> | BitmapFontData | Asset<BitmapFontData>;
/**
* The size of text (the height of each character).
*/
size?: number;
/**
* Text alignment (default "left")
*
* @since v3000.0
*/
align?: TextAlign;
/**
* The maximum width. Will wrap word around if exceed.
*/
width?: number;
/**
* The gap between each line (only available for bitmap fonts).
*
* @since v2000.2
*/
lineSpacing?: number;
/**
* The gap between each character (only available for bitmap fonts).
*
* @since v2000.2
*/
letterSpacing?: number;
/**
* The anchor point, or the pivot point. Default to "topleft".
*/
anchor?: Anchor | Vec2;
/**
* Transform the pos, scale, rotation or color for each character based on the index or char (only available for bitmap fonts).
*
* @since v2000.1
*/
transform?: CharTransform | CharTransformFunc;
/**
* Stylesheet for styled chunks, in the syntax of "this is a [stylename]styled[/stylename] word" (only available for bitmap fonts).
*
* @since v2000.2
*/
styles?: Record<string, CharTransform | CharTransformFunc>;
/**
* If true, any (whitespace) indent on the first line of the paragraph
* will be copied to all of the lines for those parts that text-wrap.
*/
indentAll?: boolean;
};
/**
* A function that returns a character transform config. Useful if you're generating dynamic styles.
*/
export type CharTransformFunc = (idx: number, ch: string) => CharTransform;
/**
* Describes how to transform each character.
*
* @group Options
*/
export interface CharTransform {
/**
* Offset to apply to the position of the text character.
* Shifts the character's position by the specified 2D vector.
*/
pos?: Vec2;
/**
* Scale transformation to apply to the text character's current scale.
* When a number, it is scaled uniformly.
* Given a 2D vector, it is scaled independently along the X and Y axis.
*/
scale?: Vec2 | number;
/**
* Increases the amount of degrees to rotate the text character.
*/
angle?: number;
/**
* Color transformation applied to the text character.
* Multiplies the current color with this color.
*/
color?: Color;
/**
* Opacity multiplication applied to the text character.
* For example, an opacity of 0.4 with 2 set in the transformation, the resulting opacity will be 0.8 (0.4 × 2).
*/
opacity?: number;
/**
* If true, the styles applied by this specific {@link DrawTextOpt.styles} entry transform
* will override, rather than compose with, the default styles given in {@link DrawTextOpt.transform} and by other
* components' styles.
*/
override?: boolean;
}
/**
* How the text should be aligned.
*
* @group Draw
*/
export type TextAlign = "center" | "left" | "right";
/**
* Formatted text with info on how and where to render each character.
*/
export type FormattedText = {
width: number;
height: number;
chars: FormattedChar[];
opt: DrawTextOpt;
renderedText: string;
};
/**
* One formated character.
*/
export interface FormattedChar {
ch: string;
tex: Texture;
width: number;
height: number;
quad: Quad;
pos: Vec2;
scale: Vec2;
angle: number;
color: Color;
opacity: number;
}
/**
* How the line should look like.
*/
export type DrawLineOpt = Omit<RenderProps, "angle" | "scale"> & {
/**
* Starting point of the line.
*/
p1: Vec2;
/**
* Ending point of the line.
*/
p2: Vec2;
/**
* The width, or thickness of the line,
*/
width?: number;
};
export type LineJoin = "none" | "round" | "bevel" | "miter";
export type LineCap = "butt" | "round" | "square";
/**
* How the lines should look like.
*/
export type DrawLinesOpt = Omit<RenderProps, "angle" | "scale"> & {
/**
* The points that should be connected with a line.
*/
pts: Vec2[];
/**
* The width, or thickness of the lines,
*/
width?: number;
/**
* The radius of each corner.
*/
radius?: number | number[];
/**
* Line join style (default "none").
*/
join?: LineJoin;
/**
* Line cap style (default "none").
*/
cap?: LineCap;
/**
* Maximum miter length, anything longer becomes bevel.
*/
miterLimit?: number;
};
/**
* How the rectangle should look like.
*/
export type DrawRectOpt = RenderProps & {
/**
* Width of the rectangle.
*/
width: number;
/**
* Height of the rectangle.
*/
height: number;
/**
* Use gradient instead of solid color.
*
* @since v3000.0
*/
gradient?: [
Color,
Color
];
/**
* If the gradient should be horizontal.
*
* @since v3000.0
*/
horizontal?: boolean;
/**
* If fill the shape with color (set this to false if you only want an outline).
*/
fill?: boolean;
/**
* The radius of each corner.
*/
radius?: number | number[];
/**
* The anchor point, or the pivot point. Default to "topleft".
*/
anchor?: Anchor | Vec2;
};
export interface Graph {
getNeighbours(node: number): number[];
getCost(node: number, neighbor: number): number;
getHeuristic(node: number, goal: number): number;
getPath(from: number, to: number): number[];
getWaypointPath(from: Vec2, to: Vec2, opt: any): Vec2[];
}
/**
* A grid is a graph consisting of connected grid cells
*/
export declare class Grid implements Graph {
private _columns;
private _rows;
private _tileWidth;
private _tileHeight;
private _data;
private _diagonals;
private _connMap;
/**
* @param data Grid data
* @param options Navigation options
*/
constructor(width: number, height: number, { diagonals, tileWidth, tileHeight }?: {
diagonals?: boolean | undefined;
tileWidth?: number | undefined;
tileHeight?: number | undefined;
});
private _buildConnectivityMap;
private _getTile;
private _getTileX;
private _getTileY;
getNeighbours(tile: number): number[];
getCost(a: number, b: number): number;
getHeuristic(a: number, b: number): number;
getPath(start: number, goal: number): number[];
getWaypointPath(start: Vec2, goal: Vec2): Vec2[];
}
declare class NavEdge {
a: Vec2;
b: Vec2;
polygon: WeakRef<NavPolygon>;
constructor(a: Vec2, b: Vec2, polygon: NavPolygon);
isLeft(x: number, y: number): number;
get middle(): Vec2;
}
declare class NavPolygon {
private _edges;
private _centroid;
private _id;
constructor(id: number);
get id(): number;
set edges(edges: NavEdge[]);
get edges(): NavEdge[];
get centroid(): Vec2;
contains(p: Vec2): boolean;
}
export declare class NavMesh implements Graph {
private _polygons;
private _pointCache;
private _edgeCache;
constructor();
private _addPoint;
private _addEdge;
private _findEdge;
private _findCommonEdge;
addPolygon(vertices: Vec2[]): NavPolygon;
addRect(pos: Vec2, size: Vec2): NavPolygon;
private _getLocation;
getNeighbours(index: number): number[];
getCost(a: number, b: number): number;
getHeuristic(indexA: number, indexB: number): number;
getPath(start: number, goal: number): number[];
getWaypointPath(start: Vec2, goal: Vec2, opt: any): Vec2[];
}
/**
* How the sprite should look like.
*/
export type DrawSpriteOpt = RenderProps & {
/**
* The sprite name in the asset manager, or the raw sprite data.
*/
sprite: string | SpriteData | Asset<SpriteData>;
/**
* If the sprite is loaded with multiple frames, or sliced, use the frame option to specify which frame to draw.
*/
frame?: number;
/**
* Width of sprite. If `height` is not specified it'll stretch with aspect ratio. If `tiled` is set to true it'll tiled to the specified width horizontally.
*/
width?: number;
/**
* Height of sprite. If `width` is not specified it'll stretch with aspect ratio. If `tiled` is set to true it'll tiled to the specified width vertically.
*/
height?: number;
/**
* When set to true, `width` and `height` will not scale the sprite but instead render multiple tiled copies of them until the specified width and height. Useful for background texture pattern etc.
*/
tiled?: boolean;
/**
* If flip the texture horizontally.
*/
flipX?: boolean;
/**
* If flip the texture vertically.
*/
flipY?: boolean;
/**
* The sub-area to render from the texture, by default it'll render the whole `quad(0, 0, 1, 1)`
*/
quad?: Quad;
/**
* The anchor point, or the pivot point. Default to "topleft".
*/
anchor?: Anchor | Vec2;
/**
* The position
*/
pos?: Vec2;
};
/**
* How the triangle should look like.
*/
export type DrawTriangleOpt = RenderProps & {
/**
* First point of triangle.
*/
p1: Vec2;
/**
* Second point of triangle.
*/
p2: Vec2;
/**
* Third point of triangle.
*/
p3: Vec2;
/**
* If fill the shape with color (set this to false if you only want an outline).
*/
fill?: boolean;
/**
* The radius of each corner.
*/
radius?: number;
};
export type ShaderData = Shader;
/**
* @group Math
*/
export type UniformValue = number | Vec2 | Color | Mat4 | number[] | Vec2[] | Color[];
/**
* @group Math
*/
export type UniformKey = Exclude<string, "u_tex">;
/**
* @group Math
*/
export type Uniform = Record<UniformKey, UniformValue>;
/**
* @group GFX
*/
export declare class Shader {
ctx: GfxCtx;
glProgram: WebGLProgram;
constructor(ctx: GfxCtx, vert: string, frag: string, attribs: string[]);
bind(): void;
unbind(): void;
send(uniform: Uniform): void;
free(): void;
}
export type AppGfxCtx = ReturnType<typeof initAppGfx>;
declare const initAppGfx: (gopt: KAPLAYOpt, ggl: GfxCtx) => {
lastDrawCalls: number;
ggl: {
gl: WebGLRenderingContext;
opts: {
texFilter?: TexFilter;
};
onDestroy: (action: () => unknown) => void;
destroy: () => void;
pushTexture2D: (item: WebGLTexture) => void;
popTexture2D: () => void;
pushArrayBuffer: (item: WebGLBuffer) => void;
popArrayBuffer: () => void;
pushElementArrayBuffer: (item: WebGLBuffer) => void;
popElementArrayBuffer: () => void;
pushFramebuffer: (item: WebGLFramebuffer) => void;
popFramebuffer: () => void;
pushRenderbuffer: (item: WebGLRenderbuffer) => void;
popRenderbuffer: () => void;
pushViewport: (item: {
x: number;
y: number;
w: number;
h: number;
}) => void;
popViewport: () => void;
pushProgram: (item: WebGLProgram) => void;
popProgram: () => void;
setVertexFormat: (fmt: VertexFormat) => void;
};
defShader: Shader;
defTex: Texture;
frameBuffer: FrameBuffer;
postShader: string | null;
postShaderUniform: Uniform | (() => Uniform) | null;
renderer: BatchRenderer;
transform: Mat4;
transformStack: Mat4[];
bgTex: Texture;
bgColor: Color | null;
bgAlpha: number;
width: number;
height: number;
viewport: {
x: number;
y: number;
width: number;
height: number;
scale: number;
};
fixed: boolean;
};
export declare class TexPacker {
private lastTextureId;
private textures;
private bigTextures;
private texturesPosition;
private canvas;
private c2d;
private x;
private y;
private curHeight;
private gfx;
private padding;
constructor(gfx: GfxCtx, w: number, h: number, padding: number);
addSingle(img: ImageSource): [
Texture,
Quad,
number
];
add(img: ImageSource): [
Texture,
Quad,
number
];
free(): void;
}
export declare class SoundData {
buf: AudioBuffer;
constructor(buf: AudioBuffer);
static fromArrayBuffer(buf: ArrayBuffer): Promise<SoundData>;
static fromURL(url: string): Promise<SoundData>;
}
/**
* Frame-based animation configuration.
*/
export type SpriteAnim = number | {
/**
* The starting frame.
*/
from?: number;
/**
* The end frame.
*/
to?: number;
/**
* If this anim should be played in loop.
*/
loop?: boolean;
/**
* When looping should it move back instead of go to start frame again.
*/
pingpong?: boolean;
/**
* This anim's speed in frames per second.
*/
speed?: number;
/**
* List of frames for the animation.
*
* If this property exists, **from, to, and pingpong will be ignored**.
*/
frames?: number[];
};
/**
* A dict of name <-> animation.
*/
export type SpriteAnims = Record<string, SpriteAnim>;
/**
* Sprite loading configuration.
*/
export interface LoadSpriteOpt {
/**
* If the defined area contains multiple sprites, how many frames are in the area horizontally.
*/
sliceX?: number;
/**
* If the defined area contains multiple sprites, how many frames are in the area vertically.
*/
sliceY?: number;
/**
* 9 slice sprite for proportional scaling.
*
* @since v3000.0
*/
slice9?: NineSlice;
/**
* Individual frames.
*
* @since v3000.0
*/
frames?: Quad[];
/**
* Animation configuration.
*/
anims?: SpriteAnims;
/**
* If the sprite is a single image.
*/
singular?: boolean;
}
export type NineSlice = {
/**
* The width of the 9-slice's left column.
*/
left: number;
/**
* The width of the 9-slice's right column.
*/
right: number;
/**
* The height of the 9-slice's top row.
*/
top: number;
/**
* The height of the 9-slice's bottom row.
*/
bottom: number;
};
export type LoadSpriteSrc = string | ImageSource;
export declare class SpriteData {
tex: Texture;
frames: Quad[];
anims: SpriteAnims;
slice9: NineSlice | null;
constructor(tex: Texture, frames?: Quad[], anims?: SpriteAnims, slice9?: NineSlice | null);
/**
* @since v3001.0
*/
get width(): number;
get height(): number;
static from(src: LoadSpriteSrc, opt?: LoadSpriteOpt): Promise<SpriteData>;
static fromImage(data: ImageSource, opt?: LoadSpriteOpt): SpriteData;
static fromURL(url: string, opt?: LoadSpriteOpt): Promise<SpriteData>;
}
/**
* An asset is a resource that is loaded asynchronously.
*/
export declare class Asset<D> {
loaded: boolean;
data: D | null;
error: Error | null;
private onLoadEvents;
private onErrorEvents;
private onFinishEvents;
constructor(loader: Promise<D>);
static loaded<D>(data: D): Asset<D>;
onLoad(action: (data: D) => void): this;
onError(action: (err: Error) => void): this;
onFinish(action: () => void): this;
then(action: (data: D) => void): Asset<D>;
catch(action: (err: Error) => void): Asset<D>;
finally(action: () => void): Asset<D>;
}
export declare class AssetBucket<D> {
assets: Map<string, Asset<D>>;
lastUID: number;
add(name: string | null, loader: Promise<D>): Asset<D>;
addLoaded(name: string | null, data: D): Asset<D>;
get(handle: string): Asset<D> | undefined;
progress(): number;
getFailedAssets(): [
string,
Asset<D>
][];
}
export type AssetsCtx = ReturnType<typeof initAssets>;
declare const initAssets: (ggl: GfxCtx, spriteAtlasPadding: number) => {
urlPrefix: string;
sprites: AssetBucket<SpriteData>;
fonts: AssetBucket<FontData>;
bitmapFonts: AssetBucket<GfxFont>;
sounds: AssetBucket<SoundData>;
shaders: AssetBucket<Shader>;
custom: AssetBucket<any>;
music: Record<string, string>;
packer: TexPacker;
loaded: boolean;
};
export type AsepriteData = {
frames: Array<{
frame: {
x: number;
y: number;
w: number;
h: number;
};
}>;
meta: {
size: {
w: number;
h: number;
};
frameTags: Array<{
name: string;
from: number;
to: number;
direction: "forward" | "reverse" | "pingpong";
}>;
};
};
export interface PeditFile {
width: number;
height: number;
frames: string[];
anims: SpriteAnims;
}
export type SpriteAtlasData = Record<string, SpriteAtlasEntry>;
/**
* A sprite in a sprite atlas.
*/
export type SpriteAtlasEntry = LoadSpriteOpt & {
/**
* X position of the top left corner.
*/
x: number;
/**
* Y position of the top left corner.
*/
y: number;
/**
* Sprite area width.
*/
width: number;
/**
* Sprite area height.
*/
height: number;
};
export type AudioCtx = ReturnType<typeof initAudio>;
declare const initAudio: () => {
ctx: AudioContext;
masterNode: GainNode;
burpSnd: SoundData;
};
export declare class Registry<T> extends Map<number, T> {
private lastID;
push(v: T): number;
pushd(v: T): () => void;
}
/**
* A controller for all events in KAPLAY.
*
* @example
* ```js
* // Create a new event
* const logHi = onUpdate(() => {
* debug.log("hi");
* });
*
* // Pause the event
* logHi.paused = true;
*
* // Cancel the event
* logHi.cancel();
*
* ```
* @group Events
*/
export declare class KEventController {
/** If the event is paused */
paused: boolean;
/** Cancel the event */
cancel: () => void;
constructor(cancel: () => void);
static join(events: KEventController[]): KEventController;
static replace(oldEv: KEventController, newEv: KEventController): KEventController;
}
export declare class KEvent<Args extends any[] = any[]> {
private cancellers;
private handlers;
add(action: (...args: Args) => unknown): KEventController;
addOnce(action: (...args: (Args | PromiseLike<Args>)[]) => void): KEventController;
next(): Promise<Args>;
trigger(...args: Args): void;
numListeners(): number;
clear(): void;
}
export declare class KEventHandler<EventMap extends Record<string, any[]>> {
private handlers;
registers: Partial<{
[Name in keyof EventMap]: Registry<(...args: EventMap[Name]) => void>;
}>;
on<Name extends keyof EventMap>(name: Name, action: (...args: EventMap[Name]) => void): KEventController;
onOnce<Name extends keyof EventMap>(name: Name, action: (...args: EventMap[Name]) => void): KEventController;
next<Name extends keyof EventMap>(name: Name): Promise<unknown>;
trigger<Name extends keyof EventMap>(name: Name, ...args: EventMap[Name]): void;
remove<Name extends keyof EventMap>(name: Name): void;
clear(): void;
numListeners<Name extends keyof EventMap>(name: Name): number;
}
export declare class BinaryHeap<T> {
_items: T[];
_compareFn: (a: T, b: T) => boolean;
/**
* Creates a binary heap with the given compare function
* Not passing a compare function will give a min heap
*/
constructor(compareFn?: (a: T, b: T) => boolean);
/**
* Insert an item into the binary heap
*/
insert(item: T): void;
/**
* Remove the smallest item from the binary heap in case of a min heap
* or the greatest item from the binary heap in case of a max heap
*/
remove(): T | null;
/**
* Remove all items
*/
clear(): void;
moveUp(pos: number): void;
moveDown(pos: number): void;
swap(index1: number, index2: number): void;
/**
* Returns the amount of items
*/
get length(): number;
}
/**
* Audio play configurations.
*/
export interface AudioPlayOpt {
/**
* If audio should start out paused.
*
* @since v3000.0
*/
paused?: boolean;
/**
* If audio should be played again from start when its ended.
*/
loop?: boolean;
/**
* Volume of audio. 1.0 means full volume, 0.5 means half volume.
*/
volume?: number;
/**
* Playback speed. 1.0 means normal playback speed, 2.0 means twice as fast.
*/
speed?: number;
/**
* Detune the sound. Every 100 means a semitone.
*
* @example
* ```js
* // play a random note in the octave
* play("noteC", {
* detune: randi(0, 12) * 100,
* })
* ```
*/
detune?: number;
/**
* The start time, in seconds.
*/
seek?: number;
/**
* The stereo pan of the sound.
* -1.0 means fully from the left channel, 0.0 means centered, 1.0 means fully right.
* Defaults to 0.0.
*/
pan?: number;
}
export interface AudioPlay {
/**
* Start playing audio.
*
* @since v3000.0
*/
play(time?: number): void;
/**
* Seek time.
*
* @since v3000.0
*/
seek(time: number): void;
/**
* Stop the sound.
*
* @since v3001.0
*/
stop(): void;
/**
* If the sound is paused.
*
* @since v2000.1
*/
paused: boolean;
/**
* Playback speed of the sound. 1.0 means normal playback speed, 2.0 means twice as fast.
*/
speed: number;
/**
* Detune the sound. Every 100 means a semitone.
*
* @example
* ```js
* // tune down a semitone
* music.detune = -100
*
* // tune up an octave
* music.detune = 1200
* ```
*/
detune: number;
/**
* Volume of the sound. 1.0 means full volume, 0.5 means half volume.
*/
volume: number;
/**
* The stereo pan of the sound.
* -1.0 means fully from the left channel, 0.0 means centered, 1.0 means fully right.
* Defaults to 0.0.
*/
pan?: number;
/**
* If the audio should start again when it ends.
*/
loop: boolean;
/**
* The current playing time (not accurate if speed is changed).
*/
time(): number;
/**
* The total duration.
*/
duration(): number;
/**
* Register an event that runs when audio ends.
*
* @since v3000.0
*/
onEnd(action: () => void): KEventController;
then(action: () => void): KEventController;
}
/**
* The {@link circle `circle()`} component.
*
* @group Component Types
*/
export interface CircleComp extends Comp {
draw: Comp["draw"];
/** Radius of circle. */
radius: number;
/**
* Render area of the circle.
*
* @since v3000.0
*/
renderArea(): Rect;
}
/**
* Options for the {@link circle `circle()``} component.
*
* @group Component Types
*/
export interface CircleCompOpt {
/**
* If fill the circle (useful if you only want to render outline with
* {@link outline `outline()`} component).
*/
fill?: boolean;
}
/**
* The {@link color `color()`} component.
*
* @group Component Types
*/
export interface ColorComp extends Comp {
color: Color;
}
/**
* The {@link mask `mask()`} component.
*
* @group Component Types
*/
export interface MaskComp extends Comp {
mask: Mask;
}
/**
* The {@link opacity `opacity()`} component.
*
* @group Component Types
*/
export interface OpacityComp extends Comp {
/** Opacity of the current object. */
opacity: number;
/** Fade in at the start. */
fadeIn(time?: number, easeFunc?: EaseFunc): TweenController;
/** Fade out at the start. */
fadeOut(time?: number, easeFunc?: EaseFunc): TweenController;
}
/**
* The {@link outline `outline()`} component.
*
* @group Component Types
*/
export interface OutlineComp extends Comp {
outline: Outline;
}
/**
* Options for the {@link particles `particles()`}'s component
*/
export type EmitterOpt = {
shape?: ShapeType;
lifetime?: number;
rate?: number;
direction: number;
spread: number;
};
/**
* Options for the {@link particles `particles()`}'s component
*
* @group Component Types
*/
export type ParticlesOpt = {
max: number;
lifeTime?: [
number,
number
];
speed?: [
number,
number
];
acceleration?: [
Vec2,
Vec2
];
damping?: [
number,
number
];
angle?: [
number,
number
];
angularVelocity?: [
number,
number
];
scales?: number[];
colors?: Color[];
opacities?: number[];
quads?: Quad[];
texture: Texture;
};
/**
* The {@link particles `particles()`} component.
*
* @group Component Types
*/
export interface ParticlesComp extends Comp {
emit(n: number): void;
onEnd(cb: () => void): void;
}
/**
* The {@link polygon `polygon()`} component.
*
* @since v3001.0
* @group Component Types
*/
export interface PolygonComp extends Comp {
draw: Comp["draw"];
/**
* Points in the polygon.
*/
pts: Vec2[];
/**
* The radius of each corner.
*/
radius?: number | number[];
/**
* The color of each vertex.
*/
colors?: Color[];
/**
* The uv of each vertex.
*
* @since v3001.0
*/
uv?: Vec2[];
/**
* The texture used when uv coordinates are present.
*
* @since v3001.0
*/
tex?: Texture;
renderArea(): Polygon;
}
/**
* Options for the {@link polygon `polygon()`} component.
*
* @group Component Types
*/
export type PolygonCompOpt = Omit<DrawPolygonOpt, "pts">;
/**
* The {@link rect `rect()`} component.
*
* @group Component Types
*/
export interface RectComp extends Comp {
draw: Comp["draw"];
/**
* Width of rectangle.
*/
width: number;
/**
* Height of rectangle.
*/
height: number;
/**
* The radius of each corner.
*/
radius?: number | [
number,
number,
number,
number
];
/**
* @since v3000.0
*/
renderArea(): Rect;
}
/**
* Options for the {@link rect `rect()`} component.
*
* @group Component Types
*/
export interface RectCompOpt {
/**
* Radius of the rectangle corners.
*/
radius?: number | [
number,
number,
number,
number
];
/**
* If fill the rectangle (useful if you only want to render outline with outline() component).
*/
fill?: boolean;
}
/**
* The {@link shader `shader()`} component.
*
* @group Component Types
*/
export interface ShaderComp extends Comp {
/**
* Uniform values to pass to the shader.
*/
uniform?: Uniform;
/**
* The shader ID.
*/
shader: string;
}
/**
* The {@link sprite `sprite()`} component.
*
* @group Component Types
*/
export interface SpriteComp extends Comp {
draw: Comp["draw"];
/**
* Name of the sprite.
*/
sprite: string;
/**
* Width for sprite.
*/
width: number;
/**
* Height for sprite.
*/
height: number;
/**
* Current frame in the entire spritesheet.
*/
frame: number;
/**
* Current frame in relative to the animation that is currently playing.
*/
animFrame: number;
/**
* The rectangular area of the texture to render.
*/
quad: Quad;
/**
* Play a piece of anim.
*/
play(anim: string, options?: SpriteAnimPlayOpt): void;
/**
* Stop current anim.
*/
stop(): void;
/**
* Get total number of frames.
*/
numFrames(): number;
/**
* Get the current animation data.
*
* @since v3001.0
*/
getCurAnim(): SpriteCurAnim | null;
/**
* Get current anim name.
*
* @deprecated Use `getCurAnim().name` instead.
*/
curAnim(): string | undefined;
/**
* Check if object's sprite has an animation.
*/
hasAnim(name: string): boolean;
/**
* Get an animation.
*/
getAnim(name: string): SpriteAnim | null;
/**
* Speed multiplier for all animations (for the actual fps for an anim use .play("anim", { speed: 10 })).
*/
animSpeed: number;
/**
* Flip texture horizontally.
*/
flipX: boolean;
/**
* Flip texture vertically.
*/
flipY: boolean;
/**
* Register an event that runs when an animation is played.
*/
onAnimStart(action: (anim: string) => void): KEventController;
/**
* Register an event that runs when an animation is ended.
*/
onAnimEnd(action: (anim: string) => void): KEventController;
/**
* @since v3000.0
*/
renderArea(): Rect;
}
/**
* Options for the {@link sprite `sprite()`} component.
*
* @group Component Types
*/
export interface SpriteCompOpt {
/**
* If the sprite is loaded with multiple frames, or sliced, use the frame option to specify which frame to draw.
*/
frame?: number;
/**
* If provided width and height, don't stretch but instead render tiled.
*/
tiled?: boolean;
/**
* Stretch sprite to a certain width.
*/
width?: number;
/**
* Stretch sprite to a certain height.
*/
height?: number;
/**
* Play an animation on start.
*/
anim?: string;
/**
* Speed multiplier for all animations (for the actual fps for an anim use .play("anim", { speed: 10 })).
*/
animSpeed?: number;
/**
* Flip texture horizontally.
*/
flipX?: boolean;
/**
* Flip texture vertically.
*/
flipY?: boolean;
/**
* The rectangular sub-area of the texture to render, default to full texture `quad(0, 0, 1, 1)`.
*/
quad?: Quad;
/**
* If fill the sprite (useful if you only want to render outline with outline() component).
*/
fill?: boolean;
}
/**
* The {@link text `text()`} component.
*
* @group Component Types
*/
export interface TextComp extends Comp {
draw: Comp["draw"];
/**
* The text to render.
*/
text: string;
/**
* The text after formatting.
*/
renderedText: string;
/**
* The text size.
*/
textSize: number;
/**
* The font to use.
*/
font: string | BitmapFontData;
/**
* Width of text.
*/
width: number;
/**
* Height of text.
*/
height: number;
/**
* Text alignment ("left", "center" or "right", default "left").
*
* @since v3000.0
*/
align: TextAlign;
/**
* The gap between each line.
*
* @since v2000.2
*/
lineSpacing: number;
/**
* The gap between each character.
*
* @since v2000.2
*/
letterSpacing: number;
/**
* Transform the pos, scale, rotation or color for each character based on the index or char.
*
* @since v2000.1
*/
textTransform: CharTransform | CharTransformFunc;
/**
* Stylesheet for styled chunks, in the syntax of "this is a [style]text[/style] word".
*
* @since v2000.2
*/
textStyles: Record<string, CharTransform | CharTransformFunc>;
/**
* @since v3000.0
*/
renderArea(): Rect;
}
/**
* Options for the {@link text `text()`} component.
*
* @group Component Types
*/
export interface TextCompOpt {
/**
* Height of text.
*/
size?: number;
/**
* The font to use.
*/
font?: string | BitmapFontData;
/**
* Wrap text to a certain width.
*/
width?: number;
/**
* Text alignment ("left", "center" or "right", default "left").
*
* @since v3000.0
*/
align?: TextAlign;
/**
* The gap between each line.
*
* @since v2000.2
*/
lineSpacing?: number;
/**
* The gap between each character.
*
* @since v2000.2
*/
letterSpacing?: number;
/**
* Transform the pos, scale, rotation or color for each character based on the index or char.
*
* @since v2000.1
*/
transform?: CharTransform | CharTransformFunc;
/**
* Stylesheet for styled chunks, in the syntax of "this is a [style]text[/style] word".
*
* @since v2000.2
*/
styles?: Record<string, CharTransform | CharTransformFunc>;
/**
* If true, any (whitespace) indent on the first line of the paragraph
* will be copied to all of the lines for those parts that text-wrap.
*/
indentAll?: boolean;
}
/**
* The {@link uvquad `uvquad()`} component.
*
* @group Component Types
*/
export interface UVQuadComp extends Comp {
draw: Comp["draw"];
/**
* Width of rect.
*/
width: number;
/**
* Height of height.
*/
height: number;
/**
* @since v3000.0
*/
renderArea(): Rect;
}
/**
* The {@link agent `agent()`} component.
*
* @group Component Types
*/
export interface AgentComp extends Comp {
agentSpeed: number;
allowDiagonals: boolean;
getDistanceToTarget(): number;
getNextLocation(): Vec2 | null;
getPath(): Vec2[] | null;
getTarget(): Vec2 | null;
isNavigationFinished(): boolean;
isTargetReachable(): boolean;
isTargetReached(): boolean;
setTarget(target: Vec2): void;
onNavigationStarted(cb: () => void): KEventController;
onNavigationNext(cb: () => void): KEventController;
onNavigationEnded(cb: () => void): KEventController;
onTargetReached(cb: () => void): KEventController;
}
/**
* Options for the {@link agent `agent()`} component.
*
* @group Component Types
*/
export type AgentCompOpt = {
speed?: number;
allowDiagonals?: boolean;
};
export interface PathfinderMapComp extends Comp {
navigate(origin: Vec2, target: Vec2, navigationOpt: any): Vec2[] | undefined;
graph: Graph | undefined;
}
export interface PathfinderMapCompOpt {
graph?: Graph;
}
export interface PathfinderComp extends Comp {
navigateTo(target: Vec2): Vec2[] | undefined;
graph: Graph | undefined;
}
export interface PathfinderCompOpt {
graph?: Graph;
navigationOpt?: any;
}
export interface PatrolComp extends Comp {
waypoints: Vec2[] | undefined;
patrolSpeed: number;
nextLocation: Vec2 | undefined;
/**
* Attaches an event handler which is called when using "stop" and the end of the path is reached.
* @param cb The event handler called when the patrol finishes.
*/
onPatrolFinished(cb: (objects: GameObj[]) => void): KEventController;
}
export type PatrolEndBehavior = "loop" | "ping-pong" | "stop";
export interface PatrolCompOpt {
waypoints?: Vec2[];
speed?: number;
endBehavior?: PatrolEndBehavior;
}
/**
* The {@link fixed `fixed()`} component.
*
* @group Component Types
*/
export interface FixedComp extends Comp {
/**
* If the obj is unaffected by camera
*/
fixed: boolean;
}
/**
* The {@link pos `pos()`} component.
*
* @group Component Types
*/
export interface PosComp extends Comp {
/**
* Object's current world position.
*/
pos: Vec2;
/**
* Move how many pixels per second. If object is 'solid', it won't move into other 'solid' objects.
*/
move(xVel: number, yVel: number): void;
move(vel: Vec2): void;
/**
* Move how many pixels, without multiplying dt, but still checking for 'solid'.
*/
moveBy(dx: number, dy: number): void;
moveBy(d: Vec2): void;
/**
* Move to a spot with a speed (pixels per second), teleports if speed is not given.
*/
moveTo(dest: Vec2, speed?: number): void;
moveTo(x: number, y: number, speed?: number): void;
/**
* Get / Set the position of the object on the screen.
*
* @since v2000.0
*/
screenPos(newPos?: Vec2): Vec2 | null;
/**
* Get / Set the position of the object relative to the root.
*
* @since v2000.0
*/
worldPos(newPos?: Vec2): Vec2 | null;
/**
* Transform a local point (relative to this) to a screen point (relative to the camera)
*/
toScreen(this: GameObj<PosComp | FixedComp>, p: Vec2): Vec2;
/**
* Transform a local point (relative to this) to a world point (relative to the root)
*
* @since v3001.0
*/
toWorld(this: GameObj<PosComp>, p: Vec2): Vec2;
/**
* Transform a screen point (relative to the camera) to a local point (relative to this)
*
* @since v3001.0
*/
fromScreen(this: GameObj<PosComp | FixedComp>, p: Vec2): Vec2;
/**
* Transform a world point (relative to the root) to a local point (relative to this)
*
* @since v3001.0
*/
fromWorld(this: GameObj<PosComp>, p: Vec2): Vec2;
/**
* Transform a point relative to this to a point relative to other
*
* @since v3001.0
*/
toOther(this: GameObj<PosComp>, other: GameObj<PosComp>, p: Vec2): Vec2;
/**
* Transform a point relative to other to a point relative to this
*
* @since v3001.0
*/
fromOther(this: GameObj<PosComp>, other: GameObj<PosComp>, p: Vec2): Vec2;
}
/**
* The {@link sentry `sentry()`} component.
*
* @group Component Types
*/
export interface SentryComp extends Comp {
direction?: Vec2;
directionAngle?: number;
fieldOfView?: number;
spotted: GameObj<any>[];
/**
* Attaches an event handler which is called when objects of interest are spotted.
* @param cb The event handler called when objects are spotted.
*/
onObjectsSpotted(cb: (objects: GameObj[]) => void): KEventController;
/**
* Returns true if the object is within the field of view.
* @param obj The object to test.
* @param direction The direction to look at.
* @param fieldOfView The field of view in degrees.
*/
isWithinFieldOfView(obj: GameObj<PosComp>, direction?: Vec2, fieldOfView?: number): boolean;
/**
* Returns true if there is a line of sight to the object.
* @param obj The object to test.
*/
hasLineOfSight(obj: GameObj<PosComp>): boolean;
}
/**
* Options for the {@link sentry `sentry()`} component.
*
* @group Component Types
*/
export interface SentryCompOpt {
direction?: Vec2 | number;
fieldOfView?: number;
lineOfSight?: boolean;
raycastExclude?: string[];
checkFrequency?: number;
}
export type SentryCandidatesCb = () => GameObj<any>[];
export type SentryCandidates = SentryCandidatesCb | QueryOpt;
/**
* The {@link tile `tile()`} component.
*
* @group Component Types
*/
export interface TileComp extends Comp {
/