silphius/app/ecs-systems/control-direction.js
2024-06-22 12:30:25 -05:00

24 lines
531 B
JavaScript

import {System} from '@/ecs/index.js';
export default class ControlDirection extends System {
tick() {
for (const {Controlled, Direction} of this.ecs.changed(['Controlled'])) {
const {moveUp, moveRight, moveDown, moveLeft} = Controlled;
if (moveUp > 0) {
Direction.direction = 0;
}
if (moveDown > 0) {
Direction.direction = 2;
}
if (moveLeft > 0) {
Direction.direction = 3;
}
if (moveRight > 0) {
Direction.direction = 1;
}
}
}
}