Browse Source

refactoring:_verbesserung_kollision

remotes/origin/branchJulia
fdai8040 11 months ago
parent
commit
c2ce23c9fd
  1. 14
      src/main/c/Pong/game.c

14
src/main/c/Pong/game.c

@ -89,6 +89,20 @@ void updateBallPosition(Ball *ball) {
ball->y += ball->speedY; 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 main(){
int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2;

Loading…
Cancel
Save