UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

28 lines (22 loc) 585 B
import { Behavior } from "../Behavior.js"; import { BehaviorStatus } from "../BehaviorStatus.js"; export class ConditionBehavior extends Behavior { /** * * @param {function():boolean} accessor */ constructor(accessor) { super(); /** * * @type {function(): boolean} * @private */ this.__accessor = accessor; } tick(timeDelta) { const v = this.__accessor(); const s = v ? BehaviorStatus.Succeeded : BehaviorStatus.Failed; return s; } }