2024-06-12 19:35:51 -05:00
|
|
|
import {System} from '@/ecs/index.js';
|
2024-07-25 02:07:36 -05:00
|
|
|
import {TAU} from '@/util/math.js';
|
2024-06-12 19:35:51 -05:00
|
|
|
|
|
|
|
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-07-25 02:07:36 -05:00
|
|
|
if (
|
|
|
|
0 === moveRight
|
|
|
|
&& 0 === moveDown
|
|
|
|
&& 0 === moveLeft
|
|
|
|
&& 0 === moveUp
|
|
|
|
) {
|
|
|
|
continue;
|
2024-06-12 19:35:51 -05:00
|
|
|
}
|
2024-07-25 02:07:36 -05:00
|
|
|
Direction.direction = (
|
|
|
|
TAU + Math.atan2(
|
|
|
|
moveDown - moveUp,
|
|
|
|
moveRight - moveLeft,
|
|
|
|
)
|
|
|
|
) % TAU;
|
2024-06-12 19:35:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|