silphius/app/ecs-systems/control-direction.js
2024-06-12 19:35:51 -05:00

28 lines
605 B
JavaScript

import {System} from '@/ecs/index.js';
export default class ControlDirection extends System {
tick() {
const {diff} = this.ecs;
for (const id in diff) {
const {Controlled} = diff[id];
if (Controlled) {
const {Controlled: {up, right, down, left}, Direction} = this.ecs.get(id);
if (up > 0) {
Direction.direction = 0;
}
if (down > 0) {
Direction.direction = 2;
}
if (left > 0) {
Direction.direction = 3;
}
if (right > 0) {
Direction.direction = 1;
}
}
}
}
}