Browse Source

Ball Kollision mit Schlägern und Wänden

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

14
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;
}

Loading…
Cancel
Save