silphius/app/ecs-systems/control-direction.js
2024-06-25 10:44:37 -05:00

27 lines
585 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 {locked, moveUp, moveRight, moveDown, moveLeft} = Controlled;
if (locked) {
continue;
}
if (moveUp > 0) {
Direction.direction = 0;
}
if (moveDown > 0) {
Direction.direction = 2;
}
if (moveLeft > 0) {
Direction.direction = 3;
}
if (moveRight > 0) {
Direction.direction = 1;
}
}
}
}