resetting when the ball goes off-screen
authorMatthew Owens <matthew@owens.tech>
Sat, 3 Oct 2020 12:05:51 +0000 (13:05 +0100)
committerMatthew Owens <matthew@owens.tech>
Sat, 3 Oct 2020 12:05:51 +0000 (13:05 +0100)
src/main.c

index 20cd0a6..e8866d5 100644 (file)
@@ -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; }
 }