From eedc47b8dde69e06aaf00dff0b221c84b14669c7 Mon Sep 17 00:00:00 2001 From: QuentiumYT <quentin.lienhardt@gmail.com> Date: Fri, 1 Oct 2021 19:32:37 +0200 Subject: [PATCH] Variation ball hit angle --- pong/server.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pong/server.js b/pong/server.js index 209c350..73fe136 100644 --- a/pong/server.js +++ b/pong/server.js @@ -148,7 +148,10 @@ setInterval(() => { ball.y - ball.r + ball.vy <= player.y + player.h && ball.y - ball.r + ball.vy > player.y) ) { - ball.a = 360 - ball.a; + let variation = + (ball.x - player.w / 2 - player.x) * + (30 / player.w); + ball.a = 360 - ball.a + variation; } } } @@ -166,7 +169,10 @@ setInterval(() => { ball.x - ball.r + ball.vx <= player.x + player.w && ball.x - ball.r + ball.vx > player.x) ) { - ball.a = 180 - ball.a; + let variation = + (ball.y - player.h / 2 - player.y) * + (30 / player.h); + ball.a = 180 - ball.a + variation; } } } -- GitLab