UNPKG

duckengine

Version:
74 lines (73 loc) 2.99 kB
import { Duck } from '../../..'; import Game from '../../game'; import Scene from '../../scene'; import PhysicsBody from '../physicsBody'; /** * @class Area * @classdesc Creates a DuckEngine Area * @description The Area Class. Detects Hitboxes entering and leaving an area * @extends PhysicsBody<'color'> * @since 2.0.0 */ export default class Area extends PhysicsBody<'color'> { /** * @memberof Area * @description An array of PhysicsBodies with Hitboxes to check for entering and leaving the area * @type PhysicsBody<Duck.Types.Texture.Type>[] * @since 2.0.0 */ collisionFilter: PhysicsBody<Duck.Types.Texture.Type>[]; /** * @memberof Area * @description An array of PhysicsBodies that are currently in the area * @type PhysicsBody<Duck.Types.Texture.Type>[] * @since 2.0.0 */ bodies: PhysicsBody<Duck.Types.Texture.Type>[]; /** * @memberof Area * @description Callback to call when a PhysicsBody with a Hitbox enters * @type ((physicsBody: PhysicsBody<Duck.Types.Texture.Type>) => unknown) | undefined * @since 2.0.0 */ onBodyEnter: ((physicsBody: PhysicsBody<Duck.Types.Texture.Type>) => unknown) | undefined; /** * @memberof Area * @description Callback to call when a PhysicsBody with a Hitbox leaves the area * @type ((physicsBody: PhysicsBody<Duck.Types.Texture.Type>) => unknown) | undefined * @since 2.0.0 */ onBodyLeave: ((physicsBody: PhysicsBody<Duck.Types.Texture.Type>) => unknown) | undefined; /** * @constructor Area * @description Creates an Area instance * @param {number} x X position of the area * @param {number} y Y position of the area * @param {number} w Width of the area * @param {number} h Height of the area * @param {PhysicsBody<Duck.Types.Texture.Type>[]} collisionFilter An array of PhysicsBodies, with Hitboxes attached to them, * to check for when it leaves/enters the area * @param {Game} game Game instance * @param {Scene} scene Scene instance * @since 2.0.0 */ constructor(x: number, y: number, w: number, h: number, collisionFilter: PhysicsBody<Duck.Types.Texture.Type>[], game: Game, scene: Scene); /** * @memberof Area * @description Updates the Area, check for Hitbox intersections with the passed collisionFilter array of PhysicsBodies * * *DO NOT CALL MANUALLY! CALLED IN SCENE.PHYSICS SERVER.__tick* * * @since 2.0.0 */ _update(): void; protected addBody(physicsBody: PhysicsBody<Duck.Types.Texture.Type>): void; protected removeBody(physicsBody: PhysicsBody<Duck.Types.Texture.Type>): void; /** * @memberof Area * @description Checks if the body is currently in the area * @param {PhysicsBody<Duck.Types.Texture.Type>} physicsBody PhysicsBody to check * @returns {boolean} */ bodyIsInArea(physicsBody: PhysicsBody<Duck.Types.Texture.Type>): boolean; }