Skip to content

Commit

Permalink
ball.y bounce player
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Sep 1, 2020
1 parent 86af1b3 commit f5c0c24
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/game.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit f5c0c24

Please sign in to comment.