aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/game.js b/game.js
index 8cf5e83..3bbfe30 100644
--- a/game.js
+++ b/game.js
@@ -261,26 +261,27 @@ function advancePhysics(deltaT) {
ballVY = -ballVY;
}
- function bounceLeft(x, y, vx, vy, pady) {
+ function bounceLeft(x, y, vx, vy, pady, padvy) {
if (x + vx * deltaT > padX + padWidth + ballRadius) return null;
const t = (padX + padWidth + ballRadius - x) / vx;
if (Math.abs((y + t * vy) - pady) >= padHeight / 2 + ballRadius) return null;
const frac = ((y + t * vy) - pady) / (padHeight / 2 + ballRadius);
- const angAdj = Math.PI / 4 * padHitAdjustCurve(frac);
+ const angAdj = Math.PI * 0.15 * padHitAdjustCurve(frac);
const curAng = Math.atan2(vy, -vx); // normal outgoing angle
const newAng = Math.max(-0.45 * Math.PI, Math.min(0.45 * Math.PI, curAng + angAdj));
const speed = Math.hypot(vx, vy);
const newvx = speed * Math.cos(newAng);
- const newvy = speed * Math.sin(newAng);
+ // TODO: not sure if simply adding of padvy to newvy is a good idea
+ const newvy = speed * Math.sin(newAng) + 0.1 * Math.abs(frac) * padvy;
const newx = x + vx * t + newvx * (deltaT - t);
const newy = y + vy * t + newvy * (deltaT - t);
return [newx, newy, newvx, newvy];
}
- let bounce = bounceLeft(ballX, ballY, ballVX, ballVY, padPos);
+ let bounce = bounceLeft(ballX, ballY, ballVX, ballVY, padPos, padVel);
if (bounce != null) {
newballX = bounce[0];
newballY = bounce[1];
@@ -289,7 +290,7 @@ function advancePhysics(deltaT) {
ret.bounce = true;
}
- bounce = bounceLeft(1 - ballX, ballY, -ballVX, ballVY, pad2Pos);
+ bounce = bounceLeft(1 - ballX, ballY, -ballVX, ballVY, pad2Pos, pad2Vel);
if (bounce != null) {
newballX = 1 - bounce[0];
newballY = bounce[1];