From fa71caa020cb87bce5dd71bc3f9a9d42d8524937 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Thu, 29 Feb 2024 21:37:31 -0500 Subject: [PATCH] [pongwars] ease nTeams --- docs/pongwars/index.html | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/pongwars/index.html b/docs/pongwars/index.html index 9bc7b6f..f5ae2ff 100644 --- a/docs/pongwars/index.html +++ b/docs/pongwars/index.html @@ -257,13 +257,13 @@ } var nTeams = teams.length; + // NTeams but with ease in to avoid instant deaths + var smoothNTeams = nTeams; function updateSquareAndBounce(x, y, dx, dy, color) { if (state[color].elim) return if (Math.max(Math.abs(dx), Math.abs(dy)) < 0.02) state[color].elim = true - nTeams = state.map(t => !t.elim).filter(Boolean).length - if (Math.min(x, y) < 0 || isNaN(x) || isNaN(y)) { console.warn(`warped ${teams[color].name}`) state[color].x = canvas.width * 0.1; @@ -281,7 +281,10 @@ } // death coefficient (if not enough territory, slow down) - const coeff = Math.min((state[color].score/(numSquaresX*numSquaresY/nTeams/mix(1.2, 4, suddenDeathCoeff))), 1.00); + var coeff = Math.min((state[color].score/(numSquaresX*numSquaresY/smoothNTeams/mix(1.2, 4, suddenDeathCoeff))), 1.00); + + // winners don't slow down + if (nTeams === 1) coeff = 1; // death coefficient when no collision const vacuumCoeff = coeff**(0.01); @@ -400,6 +403,14 @@ } function draw() { + nTeams = state.map(t => !t.elim).filter(Boolean).length; + + // practically inertia (0-1) + const smoothCoeff = 0.999; + + smoothNTeams = smoothNTeams * (smoothCoeff) + nTeams * (1 - smoothCoeff); + if (isNaN(smoothNTeams)) smoothNTeams = nTeams; + ctx.clearRect(0, 0, canvas.width, canvas.height); drawSquares();