From f46112c2fe86acba455b265c2fec93ae19bdc9a0 Mon Sep 17 00:00:00 2001 From: He4eT Date: Thu, 5 Jun 2025 18:00:37 +0200 Subject: [PATCH] game: constant speed --- game.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/game.js b/game.js index b8d408a..21011f7 100644 --- a/game.js +++ b/game.js @@ -96,10 +96,18 @@ function gameplay() { function handleMoves() { player.speed = btn(BTN_A) ? 2 : 1 - if (btn(BTN_U)) player.y = Math.max(player.y - player.speed, arena.top) - if (btn(BTN_D)) player.y = Math.min(player.y + player.speed, arena.bottom) - if (btn(BTN_L)) player.x = Math.max(player.x - player.speed, arena.left) - if (btn(BTN_R)) player.x = Math.min(player.x + player.speed, arena.right) + let dx = 0 + if (btn(BTN_L)) dx -= 1 + if (btn(BTN_R)) dx += 1 + + let dy = 0 + if (btn(BTN_U)) dy -= 1 + if (btn(BTN_D)) dy += 1 + + const norm = player.speed / ([dx, dy].every((d) => d !== 0) ? Math.SQRT2 : 1) + + player.x = Math.max(arena.left, Math.min(arena.right, player.x + dx * norm)) + player.y = Math.max(arena.top, Math.min(arena.bottom, player.y + dy * norm)) } function handleMorse() { @@ -130,7 +138,6 @@ function checkColisions() { ]) .some(([enemy, distance]) => distance < enemy.dangerZone) ) { - cls(10) currentStage = 'gameover' } }