From: Matthew Owens Date: Sat, 3 Oct 2020 12:05:51 +0000 (+0100) Subject: resetting when the ball goes off-screen X-Git-Url: https://git.owens.tech/assets/static/gitweb.css/assets/static/gitweb.css/git?a=commitdiff_plain;h=2aef7fd2fe5aba84f47187db35f70873faa6ec90;p=pong.git resetting when the ball goes off-screen --- diff --git a/src/main.c b/src/main.c index 20cd0a6..e8866d5 100644 --- a/src/main.c +++ b/src/main.c @@ -168,10 +168,11 @@ static void ball_update(const Uint8 *keyStates, float dt) ball.v.x *= -1; } if(ball.r.y + ball.r.h > windowSize.y){ - ball.r.y = windowSize.y - ball.r.h; + ball_init(); + ball.v.x = 0; ball.v.y *= -1; } - if(ball.r.y < 0 ) { ball.r.y = 0; ball.v.y *= -1; } + if(ball.r.y < 0 ) { ball.r.y = 0; ball_init(); ball.v.x = 0;} if(ball.r.x < 0 ) { ball.r.x = 0; ball.v.x *= -1; } }