]>
git.r.bdr.sh - rbdr/sumo/blob - lib/systems/reduce_velocity.js
f831f4109b3f7fb644c15d49f6802ec8ede1356e
1 import { System
} from '@serpentity/serpentity';
3 import LimitedVelocityNode
from '../nodes/limited_velocity';
6 * Reduces velocity if it exceeds threshold
8 * @extends {external:Serpentity.System}
9 * @class ReduceVelocitySystem
10 * @param {object} config a configuration object to extend.
12 export default class ReduceVelocitySystem
extends System
{
14 constructor(config
= {}) {
19 * The node collection of entities that have external force
21 * @property {external:Serpentity.NodeCollection} limitedVelocityEntities
23 * @memberof ReduceVelocitySystem
25 this.limitedVelocityEntities
= null;
29 * Initializes system when added. Requests limited velocity nodes
32 * @memberof ReduceVelocitySystem
34 * @param {external:Serpentity.Engine} engine the serpentity engine to
35 * which we are getting added
39 this.limitedVelocityEntities
= engine
.getNodes(LimitedVelocityNode
);
43 * Clears system resources when removed.
47 * @memberof ReduceVelocitySystem
51 this.limitedVelocityEntities
= null;
55 * Runs on every update of the loop. Checks current velocity and adjusts if necessary
59 * @param {Number} currentFrameDuration the duration of the current
61 * @memberof ReduceVelocitySystem
63 update(currentFrameDuration
) {
65 for (const limitedVelocityEntity
of this.limitedVelocityEntities
) {
66 console
.log(limitedVelocityEntity
.body
.body
.velocity
, limitedVelocityEntity
.maxVelocity
.maxVelocity
);