28 lines
637 B
JavaScript
28 lines
637 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: {moveUp, moveRight, moveDown, moveLeft}, Direction} = this.ecs.get(id);
|
|
if (moveUp > 0) {
|
|
Direction.direction = 0;
|
|
}
|
|
if (moveDown > 0) {
|
|
Direction.direction = 2;
|
|
}
|
|
if (moveLeft > 0) {
|
|
Direction.direction = 3;
|
|
}
|
|
if (moveRight > 0) {
|
|
Direction.direction = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|