fix: directional control

This commit is contained in:
cha0s 2024-07-25 02:07:36 -05:00
parent 14effd2455
commit 62eaa16b28

View File

@ -1,5 +1,5 @@
import {System} from '@/ecs/index.js';
import {HALF_PI} from '@/util/math.js';
import {TAU} from '@/util/math.js';
export default class ControlDirection extends System {
@ -9,18 +9,20 @@ export default class ControlDirection extends System {
if (locked) {
continue;
}
if (moveUp > 0) {
Direction.direction = HALF_PI * 3;
}
if (moveDown > 0) {
Direction.direction = HALF_PI * 1;
}
if (moveLeft > 0) {
Direction.direction = HALF_PI * 2;
}
if (moveRight > 0) {
Direction.direction = HALF_PI * 0;
if (
0 === moveRight
&& 0 === moveDown
&& 0 === moveLeft
&& 0 === moveUp
) {
continue;
}
Direction.direction = (
TAU + Math.atan2(
moveDown - moveUp,
moveRight - moveLeft,
)
) % TAU;
}
}