mirror of
https://github.com/He4eT/DotDashPit.git
synced 2026-05-04 17:37:23 +00:00
game: extract clamp function
This commit is contained in:
parent
d0e0b26411
commit
f93942d9ed
1 changed files with 4 additions and 2 deletions
6
game.js
6
game.js
|
|
@ -164,8 +164,6 @@ function handleMoves() {
|
||||||
playerStates[player.state].speed /
|
playerStates[player.state].speed /
|
||||||
([dx, dy].every((d) => d !== 0) ? Math.SQRT2 : 1)
|
([dx, dy].every((d) => d !== 0) ? Math.SQRT2 : 1)
|
||||||
|
|
||||||
const clamp = (value) => (min, max) => Math.max(min, Math.min(max, value))
|
|
||||||
|
|
||||||
player.position = {
|
player.position = {
|
||||||
x: clamp(player.position.x + dx * norm)(
|
x: clamp(player.position.x + dx * norm)(
|
||||||
arena.bounds.left,
|
arena.bounds.left,
|
||||||
|
|
@ -670,6 +668,10 @@ function arr(n, filler) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clamp(value) {
|
||||||
|
return (min, max) => Math.max(min, Math.min(max, value))
|
||||||
|
}
|
||||||
|
|
||||||
function rnd(from, to) {
|
function rnd(from, to) {
|
||||||
return Math.floor(Math.random() * (to - from + 1)) + from
|
return Math.floor(Math.random() * (to - from + 1)) + from
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue