28 lines
605 B
JavaScript
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|