UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

76 lines (75 loc) 2.13 kB
import { vec2 } from "gl-matrix"; import Collider from "./physics/collider/collider"; import RigidBody from "./physics/rigidbody"; import Shape from "./shapes/shape"; /** * Represents a generic entity in 3D space. */ export default class Entity extends RigidBody { name: string; private pieces; private zIndex; /** * Creates a new {@link Entity} instance with a position, bounding box and body pieces. * * @param position The entity's position in world space * @param collider The entity's bounding box * @param pieces The entity's body pieces for rendering * @param mass The entity's mass in kg (0 for infinite mass) * @param name A name which can be used to identify the entity */ constructor(position: vec2, collider: Collider, pieces?: Shape[], mass?: number, name?: string); /** * Sets the events that can be attached to in `listeners`. */ protected setupEvents(): void; /** * Updates the entity's physics and bounds. * * @param delta Time since last tick */ update(delta?: number): void; /** * Renders the entity's pieces. */ render(): void; /** * Sets the entity's body pieces. * * @param pieces The entity's new pieces */ setPieces(pieces: Shape[]): void; /** * Gets the entity's body pieces. * * @returns The entity's pieces */ getPieces(): Shape[]; /** * Adds a body piece to the entity. * * @param piece The piece to add to the entity */ addPiece(piece: Shape): void; /** * Removes a body piece from the entity. * * @param piece The piece to remove from the entity * @returns Wether or not the piece was removed */ removePiece(piece: Shape): boolean; /** * Sets the entites z index. * * @throws When {@link validateZIndex} returns a string. * * @param zIndex The entites new zIndex */ setZIndex(zIndex: number): void; /** * Gets the entities z index. * * @returns The entities z index */ getZIndex(): number; }