|
|
@ -157,50 +157,33 @@ int main(){ |
|
|
|
} |
|
|
|
|
|
|
|
//Bewegung Ball |
|
|
|
ball.x += ball.speedX; |
|
|
|
ball.y += ball.speedY; |
|
|
|
updateBallPosition(&ball); |
|
|
|
int result = checkCollision(ball, paddle1PositionY, paddle2PositionY); |
|
|
|
|
|
|
|
//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; |
|
|
|
} |
|
|
|
|
|
|
|
// Punkte zählen |
|
|
|
if (ball.x <= 0){ |
|
|
|
score1++; |
|
|
|
//Aktualisiert Spielstand und Ballposition |
|
|
|
if (result == 1) { |
|
|
|
score2++; |
|
|
|
ball.x = WIDTH / 2; |
|
|
|
ball.y = HEIGHT / 2; |
|
|
|
ball.speedX = -ball.speedX; |
|
|
|
} |
|
|
|
if (ball.x >= WIDTH - 1){ |
|
|
|
score2++; |
|
|
|
} else if (result == 2) { |
|
|
|
score1++; |
|
|
|
ball.x = WIDTH / 2; |
|
|
|
ball.y = HEIGHT / 2; |
|
|
|
ball.speedX = -ball.speedX; |
|
|
|
} |
|
|
|
|
|
|
|
draw Field(paddle1PositionY, paddle2PositionY, ball, score1, score2); |
|
|
|
|
|
|
|
// Spielende überprüfen |
|
|
|
if (score1 == maxScore || score2 == maxScore) { |
|
|
|
printf("Spiel beendet!\n"); |
|
|
|
if (score1 == maxScore) { |
|
|
|
printf("Spieler 1 gewinnt!\n"); |
|
|
|
} else { |
|
|
|
printf("Spieler 2 gewinnt!\n"); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
drawField(paddle1PositionY, paddle2PositionY, ball, score1, score2, 0); |
|
|
|
usleep(100000); //Verlangsamen Schleife/Spiel |
|
|
|
} |
|
|
|
|
|
|
|
clearScreen(); |
|
|
|
if (score1 == maxScore) { |
|
|
|
printf("Spieler 1 gewinnt!\n"); |
|
|
|
} else { |
|
|
|
printf("Spieler 2 gewinnt!\n"); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|