From f5c0c24650f444a248cee1e09a00d666b562a374 Mon Sep 17 00:00:00 2001 From: RodrigoDornelles Date: Tue, 1 Sep 2020 17:31:38 -0300 Subject: [PATCH] ball.y bounce player --- src/game.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game.pas b/src/game.pas index ca451fd..a8f3d7b 100644 --- a/src/game.pas +++ b/src/game.pas @@ -40,7 +40,7 @@ ball.x := screenWidth div 2; ball.y := screenHeight div 2; ballSpeed.x := -ballSpeedMin; - repeat ballSpeed.y := Randomrange(-ballSpeedMin, ballSpeedMin) until ballSpeed.x <> 0; + repeat ballSpeed.y := Randomrange(-ballSpeedMin, ballSpeedMin) until ballSpeed.y <> 0; player := RectangleCreate(padding, Trunc(screenHeight / 2) - Trunc(barSize.y / 2), Trunc(barSize.x), Trunc(barSize.y)); end; // game code @@ -49,6 +49,7 @@ if CheckCollisionCircleRec(ball, ballSize, player) then begin score := score + 1; ballSpeed.x := Abs(ballSpeed.x); + ballSpeed.y := Clamp(ballSpeed.y + Lerp(-ballSpeedMin, ballSpeedMin, (ball.y - player.y) / player.height), -ballSpeed.x, ballSpeed.x); end; // player move if IsKeyDown(KEY_UP) then player.y := max(player.y - barSpeed, 0);