From 2b8a70f000ed8139501f1ed38e13f697ef031be2 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:17:33 +0000 Subject: [PATCH] =?UTF-8?q?Ball=20Kollision=20mit=20Schl=C3=A4gern=20und?= =?UTF-8?q?=20W=C3=A4nden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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; }