game: extract clamp function

This commit is contained in:
He4eT 2025-06-16 12:50:45 +02:00
commit f93942d9ed

View file

@ -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
}