diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index c74f466..b2ca2e0 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -89,6 +89,20 @@ void updateBallPosition(Ball *ball) { ball->y += ball->speedY; } +//Verbesserung Kollision mit Schlägern&Wänden +int checkCollision(Ball ball, int paddle1PositionY, int paddle2PositionY) { + // Kollision mit Schlägern und Wänden + if (ball.y <= 0 || ball.y >= HEIGHT - 1){ + ball.speedY = -ball.speedY; + } + if (ball.x == 1 && (ball.y >= paddle2PositionY && ball.y < paddle2PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + + if (ball.x == WIDTH - 1 && (ball.y >= paddle1PositionY && ball.y < paddle1PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2;