diff --git a/lib/index.d.ts b/lib/index.d.ts index ca60682..b78fa76 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -650,7 +650,7 @@ export namespace 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, hitCallback: (e2: NumericalEntityWithHitbox | NumericalEntity) => any): void; + export function hits(entity: NumericalEntityWithHitbox | NumericalEntity, container: Container, hitCallback: (e2: T) => any): void; /** * This functions calculates whether two entities hit each other. diff --git a/lib/utilities/entity.js b/lib/utilities/entity.js index 414a7e6..736f758 100644 --- a/lib/utilities/entity.js +++ b/lib/utilities/entity.js @@ -20,7 +20,16 @@ function angle(a, b) { } function bounds(entity) { - const { w, h, pos, hitBox } = entity; + let pos, w, h, hitBox; + // Object.prototype.hasOwnProperty.call is needed because of eslint + if (Object.prototype.hasOwnProperty.call(entity, "tileW") && Object.prototype.hasOwnProperty.call(entity, "tileH")) { + ({pos, w, h} = {pos: entity.pos, w: entity.tileW, h: entity.tileH}); + } else { + ({pos, w, h} = entity); + } + + if (entity.hitBox) hitBox = entity.hitBox; + const hit = hitBox || { x: 0, y: 0, w, h }; return { x: hit.x + pos.x,