]>
git.r.bdr.sh - rbdr/sumo/blob - lib/systems/dash.js
1 import { System
} from '@serpentity/serpentity';
7 import DasherNode
from '../nodes/dasher';
10 * Applies a dash as a force on an entity. Locks it until the button is released
11 * and a cooldown period has passed
13 * @extends {external:Serpentity.System}
15 * @param {object} config a configuration object to extend.
17 export default class DashSystem
extends System
{
19 constructor(config
= {}) {
24 * The node collection of dashers
26 * @property {external:Serpentity.NodeCollection} dashers
28 * @memberof DashSystem
34 * Initializes system when added. Requests dasher nodes
37 * @memberof DashSystem
39 * @param {external:Serpentity.Engine} engine the serpentity engine to
40 * which we are getting added
44 this.dashers
= engine
.getNodes(DasherNode
);
48 * Clears system resources when removed.
52 * @memberof DashSystem
60 * Runs on every update of the loop. Triggers dash and manages cooldown
64 * @param {Number} currentFrameDuration the duration of the current
66 * @memberof DashSystem
68 update(currentFrameDuration
) {
70 for (const dasher
of this.dashers
) {
72 const dash
= dasher
.dash
;
74 if (dash
.dashing
&& !dash
.locked
) {
78 if (!dash
.dashing
&& dash
.locked
&& dash
.currentCooldown
>= dash
.cooldown
) {
83 dash
.currentCooldown
+= currentFrameDuration
;
90 // Executes the dash action
94 const dash
= dasher
.dash
;
95 const force
= dasher
.force
;
97 const angle
= force
.lastAngle
|| 0;
99 dash
.currentCooldown
= 0;
101 const xComponent
= internals
.kForce
* Math
.cos(angle
);
102 const yComponent
= internals
.kForce
* Math
.sin(angle
);
104 force
.x
+= xComponent
;
105 force
.y
+= yComponent
;
108 // Executes the unlock action
112 dasher
.dash
.locked
= false;