silphius/app/ecs-systems/apply-control-movement.js

27 lines
583 B
JavaScript
Raw Normal View History

2024-06-19 02:02:14 -05:00
import {System} from '@/ecs/index.js';
export default class ApplyControlMovement extends System {
2024-06-25 10:44:37 -05:00
static get priority() {
return {
before: 'ApplyForces',
};
}
static queries() {
return {
default: ['Controlled', 'Forces', 'Speed'],
};
}
2024-06-19 02:02:14 -05:00
tick() {
2024-06-26 07:41:07 -05:00
for (const {Controlled, Forces, Speed} of this.select('default')) {
2024-06-25 10:44:37 -05:00
if (!Controlled.locked) {
Forces.impulseX += Speed.speed * (Controlled.moveRight - Controlled.moveLeft);
Forces.impulseY += Speed.speed * (Controlled.moveDown - Controlled.moveUp);
}
2024-06-19 02:02:14 -05:00
}
}
}