diff --git a/src/entity_manager.ts b/src/entity_manager.ts index 40a53b8..bd92a67 100644 --- a/src/entity_manager.ts +++ b/src/entity_manager.ts @@ -18,16 +18,7 @@ class EntityManager { this.#entities = this.#entitiesUpdated; this.#entitiesUpdated = []; }); - } - - get entities(): Entity[] { - return this.#entities; - } - /** - * Calling this method is mandatory to start recording entities. - */ - initialize(): void { this.#triangleHook(); this.#squareHook(); @@ -40,6 +31,10 @@ class EntityManager { this.#playerHook(); } + get entities(): Entity[] { + return this.#entities; + } + /** * * @returns The own player entity @@ -66,7 +61,7 @@ class EntityManager { let parent = null; if (type == EntityType.Bullet) { // TODO: we want to change this to EntityType.Barrel in the future? - const parentIndex = this.#findEntity(EntityType.Player, position, 1000); + const parentIndex = this.#findEntity(EntityType.Player, position, 300); if (parentIndex >= 0) { parent = this.entities[parentIndex]; } @@ -89,12 +84,14 @@ class EntityManager { * Searches `#entities` for the entity that is closest to `position` and * returns the __index__ of that entity or __-1__ if there is no match. */ - #findEntity(type: EntityType, position: Vector, tolerance: number = 28): number { + #findEntity(type: EntityType, position: Vector, tolerance: number = 42): number { let result = -1; - let shortestDistance = Number.MAX_SAFE_INTEGER; + let shortestDistance = Infinity; this.#entities.forEach((x, i) => { - const distance = Vector.distance(x.predictPos(0), position); + if (x.type !== type) return; + + const distance = Vector.distance(x.position, position); if (distance < shortestDistance) { shortestDistance = distance; @@ -106,10 +103,6 @@ class EntityManager { return -1; } - if (this.#entities[result].type !== type) { - return -1; - } - return result; }