Skip to content

Commit

Permalink
added sprint/running to player (#153)
Browse files Browse the repository at this point in the history
Fixes #142
  • Loading branch information
r4pt0s authored Oct 15, 2024
2 parents 6365cec + 4fa1696 commit 7435555
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/player.controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down

0 comments on commit 7435555

Please sign in to comment.