[pongwars] fix speed limit
- also make canvas bigger
This commit is contained in:
parent
e093f44e54
commit
170aa8cee3
@ -21,7 +21,7 @@
|
|||||||
#container {
|
#container {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 750px;
|
max-width: 1000px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<canvas id="pongCanvas" width="800" height="800"></canvas>
|
<canvas id="pongCanvas" width="1200" height="800"></canvas>
|
||||||
<div id="score"></div>
|
<div id="score"></div>
|
||||||
<p id="made">
|
<p id="made">
|
||||||
made by <a href="https://koenvangilst.nl">Koen van Gilst</a> | source on
|
made by <a href="https://koenvangilst.nl">Koen van Gilst</a> | source on
|
||||||
@ -235,7 +235,7 @@
|
|||||||
if (Math.max(Math.abs(dx), Math.abs(dy)) < 0.02) state[color].elim = true
|
if (Math.max(Math.abs(dx), Math.abs(dy)) < 0.02) state[color].elim = true
|
||||||
|
|
||||||
if (Math.min(x, y) < 0 || isNaN(x) || isNaN(y)) {
|
if (Math.min(x, y) < 0 || isNaN(x) || isNaN(y)) {
|
||||||
console.log(`warped ${teams[color].name}`)
|
console.warn(`warped ${teams[color].name}`)
|
||||||
teams[color].x = canvas.width * 0.1;
|
teams[color].x = canvas.width * 0.1;
|
||||||
teams[color].y = canvas.height * 0.1;
|
teams[color].y = canvas.height * 0.1;
|
||||||
dx = 4;
|
dx = 4;
|
||||||
@ -243,7 +243,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (x > canvas.width || y > canvas.height) {
|
if (x > canvas.width || y > canvas.height) {
|
||||||
console.log(`warped ${teams[color].name}`)
|
console.warn(`warped ${teams[color].name}`)
|
||||||
teams[color].x = canvas.width * 0.9;
|
teams[color].x = canvas.width * 0.9;
|
||||||
teams[color].y = canvas.height * 0.9;
|
teams[color].y = canvas.height * 0.9;
|
||||||
dx = -4;
|
dx = -4;
|
||||||
@ -284,12 +284,12 @@
|
|||||||
updatedDx += randomNum(-0.15, mix(0.153, 0.15, suddenDeathCoeff));
|
updatedDx += randomNum(-0.15, mix(0.153, 0.15, suddenDeathCoeff));
|
||||||
updatedDy += randomNum(-0.15, 0.15);
|
updatedDy += randomNum(-0.15, 0.15);
|
||||||
const nTeams = state.map(t => !t.elim).filter(Boolean).length
|
const nTeams = state.map(t => !t.elim).filter(Boolean).length
|
||||||
const coeff = Math.min((teams[color].score/(squares.length**2/nTeams/mix(1.2, 4, suddenDeathCoeff))), 1.00);
|
const coeff = Math.min((teams[color].score/(numSquaresX*numSquaresY/nTeams/mix(1.2, 4, suddenDeathCoeff))), 1.00);
|
||||||
updatedDx *= coeff;
|
updatedDx *= coeff;
|
||||||
updatedDy *= coeff;
|
updatedDy *= coeff;
|
||||||
const speedLim = mix(100, 18, suddenDeathCoeff)
|
const speedLim = mix(30, 18, suddenDeathCoeff)
|
||||||
const norm = (updatedDx**2 + updatedDy**2)**(1/2)
|
const norm = (updatedDx**2 + updatedDy**2)**(1/2)
|
||||||
const scalar = Math.max(norm/speedLim, 1)
|
const scalar = Math.min(speedLim/norm, 1)
|
||||||
updatedDx *= scalar;
|
updatedDx *= scalar;
|
||||||
updatedDy *= scalar;
|
updatedDy *= scalar;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user