silphius/app/ecs-systems/control-direction.js

27 lines
585 B
JavaScript
Raw Normal View History

2024-06-12 19:35:51 -05:00
import {System} from '@/ecs/index.js';
export default class ControlDirection extends System {
tick() {
2024-06-22 12:30:25 -05:00
for (const {Controlled, Direction} of this.ecs.changed(['Controlled'])) {
2024-06-25 10:44:37 -05:00
const {locked, moveUp, moveRight, moveDown, moveLeft} = Controlled;
if (locked) {
continue;
}
2024-06-22 12:30:25 -05:00
if (moveUp > 0) {
Direction.direction = 0;
}
if (moveDown > 0) {
Direction.direction = 2;
}
if (moveLeft > 0) {
Direction.direction = 3;
}
if (moveRight > 0) {
Direction.direction = 1;
2024-06-12 19:35:51 -05:00
}
}
}
}