UNPKG

ridder

Version:

A straightforward game engine for simple data-driven games in JavaScript

50 lines (49 loc) 2.03 kB
import { Vector } from "./vector.js"; export type Rectangle = { x: number; y: number; w: number; h: number; }; /** * Create a new rectangle data structure. * @param x - The x-coordinate. * @param y - The y-coordinate. * @param w - The width. * @param h - The height. */ export declare function rect(x?: number, y?: number, w?: number, h?: number): Rectangle; /** * Set the components of the rectangle and returns the rectangle. */ export declare function setRectangle(r: Rectangle, x: number, y: number, w: number, h: number): Rectangle; /** * Returns `true` if the rectangle has a width and height larger than 0. */ export declare function isRectangleValid(r: Rectangle): boolean; /** * Returns `true` when the rectangles {@link a} and {@link b} intersect (overlap). */ export declare function doRectanglesIntersect(a: Rectangle, b: Rectangle): boolean; /** * Returns `true` when {@link x} and {@link y} are inside the rectangle {@link r}. */ export declare function doesRectangleContain(r: Rectangle, x: number, y: number): boolean; /** * Write the intersection (overlap) result between the rectangles {@link a} and {@link b} into the vector {@link out}. * * NOTE - This does not reset the vector {@link out} so this function can be used to accumulate the intersection result. * * @see {@link https://github.com/patrickswijgman/ridder/blob/main/examples/platformer/index.ts#L136} for an example. * * @param velocity - The velocity of rectangle {@link a} */ export declare function writeIntersectionBetweenRectangles(a: Rectangle, b: Rectangle, velocity: Vector, out: Vector): Vector; /** * Write the result of a random point between the inner and outer rectangles. */ export declare function writeRandomPointInPerimeterBetweenRectangles(outer: Rectangle, inner: Rectangle, out: Vector): void; /** * Copy the data components of rectangle {@link b} into rectangle {@link a} and returns rectangle {@link a}. */ export declare function copyRectangle(a: Rectangle, b: Rectangle): Rectangle;