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