diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 4030b11..90f45f3 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -107,12 +107,22 @@ int main(){ ball.x += ball.speedX; ball.y += ball.speedY; + //Kollision Ball (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; + } + draw Field(paddle1PositionY, paddle2PositionY); usleep(100000); //Verlangsamen Schleife/Spiel } - } - + return 0; }