From f93942d9ed4406b3cc8edb1d96dcf3a2c16ffa70 Mon Sep 17 00:00:00 2001 From: He4eT Date: Mon, 16 Jun 2025 12:50:45 +0200 Subject: [PATCH] game: extract clamp function --- game.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/game.js b/game.js index 997c0b2..54fa926 100644 --- a/game.js +++ b/game.js @@ -164,8 +164,6 @@ function handleMoves() { playerStates[player.state].speed / ([dx, dy].every((d) => d !== 0) ? Math.SQRT2 : 1) - const clamp = (value) => (min, max) => Math.max(min, Math.min(max, value)) - player.position = { x: clamp(player.position.x + dx * norm)( arena.bounds.left, @@ -670,6 +668,10 @@ function arr(n, filler) { return result } +function clamp(value) { + return (min, max) => Math.max(min, Math.min(max, value)) +} + function rnd(from, to) { return Math.floor(Math.random() * (to - from + 1)) + from }