ridder
Version:
A straightforward game engine for simple data-driven games in JavaScript
78 lines (77 loc) • 3 kB
TypeScript
export type Vector = {
x: number;
y: number;
};
/**
* Create a new vector data structure.
* A vector is a point in 2D space with an x and y coordinate.
*/
export declare function vec(x?: number, y?: number): Vector;
/**
* Set the components of the vector and returns the vector.
*/
export declare function setVector(v: Vector, x: number, y: number): Vector;
/**
* Add vector {@link b} to vector {@link a} and returns vector {@link a}.
*/
export declare function addVector(a: Vector, b: Vector): Vector;
/**
* Add vector {@link b} to vector {@link a} scaled by {@link s} and returns vector {@link a}.
*
* @example
* // Helpful when you need to scale it by the current delta. This saves you the trouble of creating another vector for the scaled version.
* addVectorScaled(position, velocity, getDelta());
*/
export declare function addVectorScaled(a: Vector, b: Vector, s: number): Vector;
/**
* Subtract vector {@link b} from vector {@link a} and returns vector {@link a}.
*/
export declare function subtractVector(a: Vector, b: Vector): Vector;
/**
* Subtract vector {@link b} from vector {@link a} scaled by {@link s} and returns vector {@link a}.
*
* @example
* // Helpful when you need to scale it by the current delta. This saves you the trouble of creating another vector for the scaled version.
* subtractVectorScaled(position, velocity, getDelta());
*/
export declare function subtractVectorScaled(a: Vector, b: Vector, s: number): Vector;
/**
* Scale the vector by the given scalar and returns the vector.
*/
export declare function scaleVector(v: Vector, s: number): Vector;
/**
* Reset the vector's components back to zero and returns the vector.
*/
export declare function resetVector(v: Vector): Vector;
/**
* Copy the components of vector {@link b} into vector {@link a} and returns vector {@link a}.
*/
export declare function copyVector(a: Vector, b: Vector): Vector;
/**
* Point the vector in the direction of the given angle in degrees, while maintaining its length and returns the vector.
*/
export declare function angleVector(v: Vector, degrees: number): Vector;
/**
* Linearly interpolate the vector {@link v} to the value {@link to} using the scalar value {@link t} and returns the vector.
*/
export declare function lerpVector(v: Vector, to: number, t: number): Vector;
/**
* Normalize the vector, making it's length 1 and returns the vector.
*/
export declare function normalizeVector(v: Vector): Vector;
/**
* Limit the vector's length by the given value.
*/
export declare function limitVector(v: Vector, max: number): Vector;
/**
* Create a new vector data structure using the given vector's components.
*/
export declare function cloneVector(v: Vector): Vector;
/**
* Get the length (magnitude) of the vector.
*/
export declare function getVectorLength(v: Vector): number;
/**
* Get the distance between vector {@link a} and vector {@link b}.
*/
export declare function getVectorDistance(a: Vector, b: Vector): number;