import {System} from '@/ecs/index.js'; import {TAU} from '@/util/math.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 ( 0 === moveRight && 0 === moveDown && 0 === moveLeft && 0 === moveUp ) { continue; } Direction.direction = ( TAU + Math.atan2( moveDown - moveUp, moveRight - moveLeft, ) ) % TAU; } } }