From 7fcd39c728d16899725e76833675d78ba0f59acd Mon Sep 17 00:00:00 2001 From: Harshil Patel <26harshilpatel11@gmail.com> Date: Mon, 14 Oct 2024 18:48:15 -0400 Subject: [PATCH 1/2] added sprint/running to player --- src/player.controls.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/player.controls.js b/src/player.controls.js index 886cd37..e197fad 100644 --- a/src/player.controls.js +++ b/src/player.controls.js @@ -62,11 +62,15 @@ export const addPlayerControls = (player) => { const dirX = pressed.has('left') ? -1 : pressed.has('right') ? 1 : 0; const dirY = pressed.has('up') ? -1 : pressed.has('down') ? 1 : 0; const moveDir = k.vec2(dirX, dirY); + const speed = pressed.size === 1 - ? player.speed - : // Dot product for diagonal movement 45% - player.speed * 0.707106781188095; // 1 / sqrt(2) + ? player.state.energy > 50 + ? player.speed * 1.25 + : player.speed * 1.1 + : player.state.energy > 50 + ? player.speed * 0.707106781188095 * 1.25 // Dot product for diagonal movement 45% + : player.speed * 0.707106781188095 * 1.1; player.move(moveDir.unit().scale(speed)); }); From 4fa1696566ba3f6f5c02c0c1e4791aa629d2ecd9 Mon Sep 17 00:00:00 2001 From: Harshil Patel <26harshilpatel11@gmail.com> Date: Mon, 14 Oct 2024 18:55:22 -0400 Subject: [PATCH 2/2] Update condition to check energy to check energy is 50% or higher --- src/player.controls.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/player.controls.js b/src/player.controls.js index e197fad..0443f69 100644 --- a/src/player.controls.js +++ b/src/player.controls.js @@ -65,10 +65,10 @@ export const addPlayerControls = (player) => { const speed = pressed.size === 1 - ? player.state.energy > 50 + ? player.state.energy >= 50 ? player.speed * 1.25 : player.speed * 1.1 - : player.state.energy > 50 + : player.state.energy >= 50 ? player.speed * 0.707106781188095 * 1.25 // Dot product for diagonal movement 45% : player.speed * 0.707106781188095 * 1.1;