From c2ce23c9fd2bcaceb3ba749850652ee4b974c02d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:46:17 +0000 Subject: [PATCH] refactoring:_verbesserung_kollision --- src/main/c/Pong/game.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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;