UNPKG

@fuwu-yuan/bgew

Version:

Baguette Game Engine Web is a french 2D Web game engine

216 lines (215 loc) 6.81 kB
import { Dispatcher, DispatcherOptions } from "../classes/Dispatcher"; import { Board } from "./board"; import { Container } from "./entities"; import { Body, Result } from "detect-collisions"; /** * The most important part of your game * To build a game, you need to create entities and add it to your board * */ export declare abstract class Entity { private static __AI; private _parent; protected _id: string; protected _rotate: number; protected _zoom: number; protected _x: number; protected _y: number; private _speedX; private _speedY; protected _width: number; protected _height: number; protected _dispatcher: Dispatcher; protected _board: Board | null; protected _visible: boolean; hovered: boolean; protected _disabled: boolean; protected _focus: boolean; protected _solid: boolean; protected _weight: number; protected _gravitySpeed: number; protected _falling: boolean; protected _body: Body; protected _opacity: number; protected constructor(x: number, y: number, width: number, height: number, id?: string); init(board: Board): void; get parent(): Container | null; set parent(value: Container | null); get board(): Board | null; set board(value: Board | null); get rotate(): number; set rotate(angle: number); get zoom(): number; set zoom(value: number); get id(): string; /** * BE AWARE : if you change entity id after registered event listeners, events will not be triggered anymore for this entity, you will need to remove event listeners and register it again. * @param id */ set id(id: string); get x(): number; set x(value: number); get y(): number; set y(value: number); /** * Get directionX in radian */ /** * Set directionX in radian * @param value in radian */ /** * Get directionY in radian */ /** * Set directionY in radian * @param value in radian */ /** * Get direction in radian<br> * To get degrees use {@link Entity.directionDegrees} */ /** * Set direction in radian<br> * To use degrees use {@link Entity.directionDegrees} * @param value in radian */ /** * Get the direction in degrees */ /** * Set the direction in degrees * @param value in degrees */ /** * Get entity speedX */ get speedX(): number; /** * Set entity speedX * @param value */ set speedX(value: number); /** * Get entity speedY */ get speedY(): number; /** * Set entity speedY * @param value */ set speedY(value: number); /** * * Set entity speed in specified angle in radian or degrees * * @param speed in pixel per seconds * @param angle in radian or degrees * @param degrees true if angle is in degrees (default: radian) */ setSpeedWithAngle(speed: number, angle: number, degrees?: boolean): void; /** * Set entity speed keeping current angle (default angle : atan2(-0, 0) = 0 rad) * @param value */ set speed(value: number); /** * Get current speed (depending on speedX and speedY) */ get speed(): number; /** * Get current angle in radian (depending on speedX and speedY). Default angle : atan2(-0, 0) = 0 rad */ get angle(): number; /** * Set angle in radian keeping current speed (will update speedX and speedY) keeping global speed * * @param value */ set angle(value: number); /** * Get current angle in degrees */ get angleInDegrees(): number; /** * Set angle in degrees keeping current speed (will update speedX and speedY) keeping global speed * @see Entity.angle * @param value */ set angleInDegrees(value: number); get absX(): number; get absY(): number; get height(): number; set height(value: number); get width(): number; set width(value: number); get visible(): boolean; set visible(value: boolean); get dispatcher(): Dispatcher; get solid(): boolean; set solid(value: boolean); get weight(): number; set weight(value: number); get falling(): boolean; set falling(value: boolean); intersect(x: number, y: number, event?: Event | null, depth?: number): boolean; intersectWithEntity(entity: Entity): boolean; /** * Check if entity intersect with any of the given entities * @param entities Entities to check collision * @return An array containing intersecting entities */ intersectWithEntities(entities: Entity[]): Entity[]; /** * Listen mouse event on this entity * @param event An event from this list : click, dblclick, contextmenu, mousedown, mouseup, mouseenter, mouseleave, mousemove, all * @param callback * @param options */ onMouseEvent(event: "click" | "dblclick" | "contextmenu" | "mousedown" | "mouseup" | "mouseenter" | "mouseleave" | "mousemove" | "all", callback: (event: MouseEvent, x: number, y: number) => void, options?: DispatcherOptions): void; /** * Listen mouse event on this entity * @param event An event from this list : keyup, keydown, keypress, all * @param callback * @param options */ onKeyboardEvent(event: "keyup" | "keydown" | "keypress" | "all", callback: (event: KeyboardEvent) => void, options?: DispatcherOptions): void; /** * Listen for entity intersect with x and y * @param x * @param y * @param callback * @param options */ onIntersect(x: number, y: number, callback: (entity: Entity, point: { x: number; y: number; }) => void, options?: DispatcherOptions): void; /** * Listen for the two entities intersection * @param entity * @param callback * @param options */ onIntersectWithEntity(entity: Entity, callback: (entity: Entity, collisionWith: Entity, result: Result) => void, options?: DispatcherOptions): void; onIntersectWithAnyEntity(callback: (entity: Entity, collisionWith: Entity, result: Result) => void, options?: DispatcherOptions): void; getPath2D(): Path2D; get body(): Body; get opacity(): number; set opacity(value: number); debug(ctx: CanvasRenderingContext2D): void; reset(): void; draw(ctx: CanvasRenderingContext2D): void; onDestroy(): void; update(delta: number): void; private updateGravity; private updateSpeed; checkCollisions(): void; /********************* * Getters & Setters * *********************/ get disabled(): boolean; set disabled(value: boolean); get focus(): boolean; set focus(value: boolean); }