diff options
Diffstat (limited to 'lib/systems/reduce_velocity.js')
| -rw-r--r-- | lib/systems/reduce_velocity.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/systems/reduce_velocity.js b/lib/systems/reduce_velocity.js new file mode 100644 index 0000000..6521014 --- /dev/null +++ b/lib/systems/reduce_velocity.js @@ -0,0 +1,70 @@ +import { System } from '@serpentity/serpentity'; + +import LimitedVelocityNode from '../nodes/limited_velocity'; + +/** + * Reduces velocity if it exceeds threshold + * + * @extends {external:Serpentity.System} + * @class ReduceVelocitySystem + * @param {object} config a configuration object to extend. + */ +export default class ReduceVelocitySystem extends System { + + constructor(config = {}) { + + super(); + + /** + * The node collection of entities that have external force + * + * @property {external:Serpentity.NodeCollection} limitedVelocityEntities + * @instance + * @memberof ReduceVelocitySystem + */ + this.limitedVelocityEntities = null; + } + + /** + * Initializes system when added. Requests limited velocity nodes + * + * @function added + * @memberof ReduceVelocitySystem + * @instance + * @param {external:Serpentity.Engine} engine the serpentity engine to + * which we are getting added + */ + added(engine) { + + this.limitedVelocityEntities = engine.getNodes(LimitedVelocityNode); + } + + /** + * Clears system resources when removed. + * + * @function removed + * @instance + * @memberof ReduceVelocitySystem + */ + removed() { + + this.limitedVelocityEntities = null; + } + + /** + * Runs on every update of the loop. Checks current velocity and adjusts if necessary + * + * @function update + * @instance + * @param {Number} currentFrameDuration the duration of the current + * frame + * @memberof ReduceVelocitySystem + */ + update(currentFrameDuration) { + + for (const limitedVelocityEntity of this.limitedVelocityEntities) { + console.log(limitedVelocityEntity.body.body.velocity, limitedVelocityEntity.maxVelocity.maxVelocity); + } + } +}; + |