blob: f831f4109b3f7fb644c15d49f6802ec8ede1356e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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);
}
}
}
|