Merge branch 'master' of https://gitea.arnweb.nl/arne/asdf-games
This commit is contained in:
commit
8ea643b1bb
305
lib/index.d.ts
vendored
305
lib/index.d.ts
vendored
@ -87,6 +87,52 @@ export class TileMap extends Container<TileSprite> {
|
||||
* @param texture Texture instance of source image file
|
||||
*/
|
||||
constructor(tiles: Coordinates[], mapW: number, mapH: number, tileW: number, tileH: number, texture: Texture);
|
||||
|
||||
/**
|
||||
* Calculates in which tile a pixel is located.
|
||||
* @param pos The position of the pixel.
|
||||
*/
|
||||
pixelToMapPos(pos: Coordinates): Coordinates
|
||||
|
||||
/**
|
||||
* Calculates the pixel position of a tile in a map.
|
||||
* @param pos The position of the tile in the map.
|
||||
*/
|
||||
mapToPixelPos(pos: Coordinates): Coordinates
|
||||
|
||||
/**
|
||||
* Returns the TileSprite at a given map position.
|
||||
* @param mapPos the tile of a given position.
|
||||
*/
|
||||
tileAtMapPos(mapPos: Coordinates): TileSprite
|
||||
|
||||
/**
|
||||
* Returns the TileSprite at a given pixel position.
|
||||
* @param pos The pixel position of the tile
|
||||
*/
|
||||
tileAtPixelPos(pos: Coordinates): TileSprite
|
||||
|
||||
/**
|
||||
* Changes the frame attribute of the TileSprite at the given mapPos.
|
||||
* @param mapPos the map position of the tile.
|
||||
* @param frame the new value for the frame attribute.
|
||||
*/
|
||||
setFrameAtMapPos(mapPos: Coordinates, frame: Coordinates): TileSprite
|
||||
|
||||
/**
|
||||
* Changes the frame attribute of the TileSprite at the given pixel position.
|
||||
* @param mapPos the pixel position of the tile.
|
||||
* @param frame the new value for the frame attribute.
|
||||
*/
|
||||
setFrameAtPixelPos(pos: Coordinates, frame: Coordinates): TileSprite
|
||||
|
||||
/**
|
||||
* Returns the tiles at the corner of the bounds.
|
||||
* @param bounds a rectangle which defines what the corner are.
|
||||
* @param xo offset to the x values.
|
||||
* @param yo offset to the y values.
|
||||
*/
|
||||
tilesAtCorners(bounds: {x: number, y: number, w: number, h: number}, xo?: number, yo?: number): TileSprite[]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,9 +295,9 @@ export class Container<T> {
|
||||
* Updates all children when called
|
||||
* @param dt Delta time
|
||||
* @param t Total time
|
||||
* @returns Returns if the child is dead or not
|
||||
* @returns Returns anything
|
||||
*/
|
||||
update(dt: number, t: number): boolean;
|
||||
update(dt: number, t: number): any;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,6 +367,24 @@ export class KeyControls {
|
||||
*/
|
||||
get action(): boolean;
|
||||
|
||||
/**
|
||||
* Returns value of ctrl key.
|
||||
* @returns Key value
|
||||
*/
|
||||
get ctrl(): boolean;
|
||||
|
||||
/**
|
||||
* Returns value of shift key.
|
||||
* @returns Key value
|
||||
*/
|
||||
get shift(): boolean;
|
||||
|
||||
/**
|
||||
* Returns value of escape key.
|
||||
* @returns Key value
|
||||
*/
|
||||
get escape(): boolean;
|
||||
|
||||
/**
|
||||
* Returns -1 on Arrow Left or A
|
||||
*
|
||||
@ -346,7 +410,7 @@ export class KeyControls {
|
||||
key(key: number, value: boolean): boolean;
|
||||
|
||||
/**
|
||||
* Resets default value to all keys
|
||||
* Resets default value (false) to all keys
|
||||
*/
|
||||
reset(): void;
|
||||
}
|
||||
@ -381,7 +445,242 @@ export class CanvasRenderer {
|
||||
render(container: Container<unknown>, clear?: boolean): void
|
||||
}
|
||||
|
||||
/**
|
||||
* Anim represents a single animation.
|
||||
*/
|
||||
declare class Anim {
|
||||
|
||||
curTime: number;
|
||||
frames: Coordinates[];
|
||||
rate: number;
|
||||
curFrame: number;
|
||||
frame: Coordinates;
|
||||
|
||||
/**
|
||||
* Constructor for an animation.
|
||||
* @param frames A collection of coordinates for each frame in the texture file.
|
||||
* @param rate The rate at which the animation plays.
|
||||
*/
|
||||
constructor(frames: Coordinates[], rate: number);
|
||||
|
||||
/**
|
||||
* Resets the animation to the first frame.
|
||||
*/
|
||||
reset(): void;
|
||||
|
||||
/**
|
||||
* Causes the animation to update based on dt.
|
||||
* @param dt Delta time
|
||||
*/
|
||||
update(dt: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The AnimManager class
|
||||
*/
|
||||
export class AnimManager {
|
||||
|
||||
anims: {
|
||||
[name: string]: Anim
|
||||
}
|
||||
running: boolean;
|
||||
frameSource: Coordinates;
|
||||
current: string | null;
|
||||
|
||||
constructor(e: Coordinates);
|
||||
|
||||
/**
|
||||
* Adds an animation to the AnimManager
|
||||
* @param name The name for the animation
|
||||
* @param frames Where each frame is located in the texture
|
||||
* @param speed The speed at which the animation plays.
|
||||
*/
|
||||
add(name: string, frames: Coordinates[], speed: number): Anim;
|
||||
|
||||
/**
|
||||
* Updates the current animation.
|
||||
* @param dt delta time
|
||||
*/
|
||||
update(dt: number): void;
|
||||
|
||||
/**
|
||||
* Starts playing an animation.
|
||||
* @param anim The name of the animation
|
||||
*/
|
||||
play(anim: string): void;
|
||||
|
||||
/**
|
||||
* Stops playing any animation
|
||||
*/
|
||||
stop(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Rect class
|
||||
*/
|
||||
export class Rect {
|
||||
|
||||
pos: Coordinates
|
||||
w: number;
|
||||
h: number;
|
||||
style: {
|
||||
fill: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a rectangle.
|
||||
* @param w The width of the rectangle
|
||||
* @param h The height of the rectangle
|
||||
* @param style The styles of the rectangle
|
||||
*/
|
||||
constructor(w: number, h: number, style: { fill: string })
|
||||
}
|
||||
|
||||
export class Camera extends Container<unknown> {
|
||||
|
||||
w: number;
|
||||
h: number;
|
||||
worldSize: {w: number, h: number};
|
||||
offset: Coordinates;
|
||||
subject: Coordinates;
|
||||
|
||||
/**
|
||||
* Constructs a camera object. This can be fed into the main scene: `scene.add(camera);`
|
||||
* @param subject The entity on which should be focused
|
||||
* @param viewport the size of the viewport - how much should be visible.
|
||||
* @param worldSize the size of the whole map.
|
||||
*/
|
||||
constructor(subject: NumericalEntity | Coordinates, viewport: {w: number, h: number}, worldSize: {w: number, h: number})
|
||||
|
||||
/**
|
||||
* Sets the subject of the camera.
|
||||
* @param e The entity that needs to be set as subject.
|
||||
*/
|
||||
setSubject(e: NumericalEntity | Coordinates): void;
|
||||
|
||||
/**
|
||||
* Moves the camera to the subject
|
||||
*/
|
||||
focus(): void;
|
||||
|
||||
/**
|
||||
* update function for the container.
|
||||
* @param t the elapsed time
|
||||
* @param dt delta time
|
||||
*/
|
||||
update(t: number, dt: number): void;
|
||||
}
|
||||
|
||||
interface NumericalEntity {pos: Coordinates, w: number, h: number}
|
||||
|
||||
interface NumericalEntityWithHitbox extends NumericalEntity {hitBox: NumericalEntity}
|
||||
|
||||
export namespace deadInTracks {
|
||||
/**
|
||||
* This functions checks whether ent walks against a non-walkable object and whether it should move in the x and y position and how much.
|
||||
* The difference with wallslide is that deadInTracks stops the entity entirely when it touches a non-walkable surface.
|
||||
* wallslide will move the entity in x or y if possible.
|
||||
* @param ent The entity that is moving.
|
||||
* @param map The TileMap the entity moves on.
|
||||
* @param x The maximal movement on the x. default is 0
|
||||
* @param y The maximal movement on the y. default is 0
|
||||
* @returns Coordinates of how much the entity walks in x and y.
|
||||
*/
|
||||
export function deadInTracks(ent: NumericalEntity | NumericalEntityWithHitbox, map: TileMap, x?: number, y?: number): Coordinates;
|
||||
}
|
||||
|
||||
export namespace wallslide {
|
||||
/**
|
||||
* This functions checks whether ent walks against a non-walkable object and whether it should move in the x and y position and how much.
|
||||
* The difference with wallslide is that deadInTracks stops the entity entirely when it touches a non-walkable surface.
|
||||
* wallslide will move the entity in x or y if possible.
|
||||
* @param ent The entity that is moving.
|
||||
* @param map The TileMap the entity moves on.
|
||||
* @param x The maximal movement on the x. default is 0
|
||||
* @param y The maximal movement on the y. default is 0
|
||||
* @returns Coordinates of how much the entity walks in x and y.
|
||||
*/
|
||||
export function wallslide(ent: NumericalEntity | NumericalEntityWithHitbox, map: TileMap, x?: number, y?: number): Coordinates;
|
||||
}
|
||||
|
||||
export namespace entity {
|
||||
|
||||
/**
|
||||
* addDebug adds a red border around the hitboxes of an entity.
|
||||
* @param e The entity.
|
||||
*/
|
||||
export function addDebug<T extends Container<unknown> | NumericalEntityWithHitbox>(e: T): T;
|
||||
|
||||
/**
|
||||
* This function checks if an entity hits anything in a container.
|
||||
* @param entity The entity.
|
||||
* @param container The container.
|
||||
* @param hitCallback The callback that is executed when an entity hits something in the container.
|
||||
*/
|
||||
export function hits(entity: NumericalEntityWithHitbox | NumericalEntity, container: Container<NumericalEntityWithHitbox | NumericalEntity>, hitCallback: (e2: NumericalEntityWithHitbox | NumericalEntity) => any): void;
|
||||
|
||||
/**
|
||||
* This functions calculates whether two entities hit each other.
|
||||
* @param e1 The first entity.
|
||||
* @param e2 The second entity.
|
||||
*/
|
||||
export function hit(e1: NumericalEntityWithHitbox | NumericalEntity, e2: NumericalEntityWithHitbox | NumericalEntity): boolean;
|
||||
|
||||
/**
|
||||
* This function calculates the angle relative to the x-axis between the centers of two entities.
|
||||
* @param a The first entity.
|
||||
* @param b The second entity.
|
||||
* @returns the angle in radians.
|
||||
*/
|
||||
export function angle(a: NumericalEntity, b: NumericalEntity): number;
|
||||
|
||||
/**
|
||||
* This function calculates the full hitbox of an entity.
|
||||
* @param entity The enitity
|
||||
*/
|
||||
export function bounds(entity: NumericalEntityWithHitbox | NumericalEntity): {x: number, y: number, w: number, h: number};
|
||||
|
||||
/**
|
||||
* This function calculates the distance between the centers of two entities.
|
||||
* @param a The first entity.
|
||||
* @param b The second entity.
|
||||
*/
|
||||
export function distance(a: NumericalEntity, b: NumericalEntity): number;
|
||||
|
||||
/**
|
||||
* This function calculates the center of an entity.
|
||||
* @param entity The entity to calculate the center of.
|
||||
*/
|
||||
export function center(entity: NumericalEntity): number;
|
||||
|
||||
}
|
||||
|
||||
export namespace math {
|
||||
|
||||
/**
|
||||
* This function calculates the angle relative from the x-axis between two points.
|
||||
* @param a The first point.
|
||||
* @param b The second point.
|
||||
* @returns The angle in radians.
|
||||
*/
|
||||
export function angle(a: Coordinates, b: Coordinates): number;
|
||||
|
||||
/**
|
||||
* This function calculates if x is between min and max.
|
||||
* @param x A numerical value
|
||||
* @param min A numerical value
|
||||
* @param max A numerical value
|
||||
* @returns x if x is between min and max.
|
||||
*/
|
||||
export function clamp(x: number, min: number, max: number): number;
|
||||
|
||||
/**
|
||||
* Calculates the distance between two points
|
||||
* @param a The first point.
|
||||
* @param b The second point.
|
||||
*/
|
||||
export function distance(a: Coordinates, b: Coordinates): number;
|
||||
|
||||
/**
|
||||
* Returns random integer between min and max
|
||||
* @param min Minimum value
|
||||
|
Loading…
Reference in New Issue
Block a user