ridder
Version:
A straightforward game engine for simple data-driven games in JavaScript
69 lines (68 loc) • 2.65 kB
TypeScript
/**
* Convert the given degrees to radians.
*/
export declare function toRadians(degrees: number): number;
/**
* Convert the given radians to degrees.
*/
export declare function toDegrees(radians: number): number;
/**
* Clamp a value between the given minimum and maximum values.
* If it's lower than the minimum value the minimum value is returned, if it's higher than the maximum value the maximum value is returned.
*/
export declare function clamp(value: number, min: number, max: number): number;
/**
* Return the linearly interpolated value between the values {@link a} and {@link b} using the scalar value {@link t}.
*/
export declare function lerp(a: number, b: number, t: number): number;
/**
* Get the distance between two points.
* @param x1 - The x coordinate of the first point.
* @param y1 - The y coordinate of the first point.
* @param x2 - The x coordinate of the second point.
* @param y2 - The y coordinate of the second point.
*/
export declare function getDistance(x1: number, y1: number, x2: number, y2: number): number;
/**
* Get the angle in degrees between two points.
* @param x1 - The x coordinate of the first point.
* @param y1 - The y coordinate of the first point.
* @param x2 - The x coordinate of the second point.
* @param y2 - The y coordinate of the second point.
*/
export declare function getAngle(x1: number, y1: number, x2: number, y2: number): number;
/**
* Get a new UUID using the browser's crypto API.
*
* NOTE - You do need a web server with HTTPS (localhost excluded) for this to work.
*/
export declare function uuid(): `${string}-${string}-${string}-${string}-${string}`;
/**
* Get a random number between min and max (inclusive).
*/
export declare function random(min: number, max: number): number;
/**
* Roll for a chance to win!
* @param chance - A value between 0 and 1, e.g. 0.4 for 40% chance.
*/
export declare function roll(chance: number): boolean;
/**
* Get a random element from the array.
*/
export declare function pick<T>(a: Array<T>): T;
/**
* Shuffle the array in-place using the Fisher-Yates algorithm.
*/
export declare function shuffle<T>(a: T[]): T[];
/**
* Removes the first-found element from the array in-place.
*/
export declare function remove<T>(a: Array<T>, e: T): T[];
/**
* Repeat the action {@link x} times.
*/
export declare function repeat(x: number, action: (x: number) => void): void;
/**
* Create a new canvas element with the given width and height, returns a tuple with the canvas and its 2D context.
*/
export declare function createCanvas(width: number, height: number): readonly [HTMLCanvasElement, CanvasRenderingContext2D];