silphius/app/ecs-systems/apply-control-movement.js
2024-06-26 07:41:07 -05:00

27 lines
583 B
JavaScript

import {System} from '@/ecs/index.js';
export default class ApplyControlMovement extends System {
static get priority() {
return {
before: 'ApplyForces',
};
}
static queries() {
return {
default: ['Controlled', 'Forces', 'Speed'],
};
}
tick() {
for (const {Controlled, Forces, Speed} of this.select('default')) {
if (!Controlled.locked) {
Forces.impulseX += Speed.speed * (Controlled.moveRight - Controlled.moveLeft);
Forces.impulseY += Speed.speed * (Controlled.moveDown - Controlled.moveUp);
}
}
}
}