UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

49 lines (37 loc) 1.19 kB
import { assert } from "../../../../core/assert.js"; import { BehaviorStatus } from "../BehaviorStatus.js"; import { EntityBehavior } from "./EntityBehavior.js"; /** * Causes another entity to be destroyed * Will produce a {@link BehaviorStatus.Failed} if entity could not be destroyed, either because it doesn't exist or the reference is stale * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export class KillBehavior extends EntityBehavior { /** * @type {EntityReference} */ #ref; /** * * @param {EntityReference} ref * @returns {KillBehavior} */ static create(ref) { assert.defined(ref, 'ref'); assert.isObject(ref, 'ref'); assert.equal(ref.isEntityReference, true, 'ref.isEntityReference !== true'); const r = new KillBehavior(); r.#ref = ref; return r; } tick(timeDelta) { const ecd = this.ecd; if (this.#ref.destroy(ecd)) { return BehaviorStatus.Succeeded; } else { // couldn't find return BehaviorStatus.Failed; } } }