From 62eaa16b2873d2188b7a93e3c8501ff4d6f39bac Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 25 Jul 2024 02:07:36 -0500 Subject: [PATCH] fix: directional control --- app/ecs/systems/control-direction.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/ecs/systems/control-direction.js b/app/ecs/systems/control-direction.js index 251e8a6..da12018 100644 --- a/app/ecs/systems/control-direction.js +++ b/app/ecs/systems/control-direction.js @@ -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; } }