#define PADDLESIZE 10
#define HEIGHT 100
+static int AI = 0;
static int p1move = 0;
static int p2move = 0;
static int score1 = 0;
}
static void run(void) {
+ // AI
+ if(AI) {
+ if(ballY < paddle2 - PADDLESIZE)
+ p2move = -1;
+ else if(ballY > paddle2 + PADDLESIZE)
+ p2move = 1;
+ else
+ p2move = 0;
+ }
+
// Move the paddles
paddle1 += p1move * PADDLESPEED;
paddle2 += p2move * PADDLESPEED;
if(ballX >= HEIGHT) {
++score1;
initball();
- return;
}
if(ballX <= -HEIGHT) {
++score2;
initball();
- return;
}
// Move the ball
ballX += ballVecX;
ballY += ballVecY;
+
+ // Check scores for winners..
+ if(score1 == 9) {
+ // Player 1 wins
+ score1 = score2 = 0;
+ }
+ if(score2 == 9) {
+ // Player 2 wins
+ score1 = score2 = 0;
+ }
}
static void display(void) {
}
int main(int argc, char *argv[]) {
+ if(argc == 2 && *argv[1] == '1') {
+ AI = 1;
+ }
+
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutInit(&argc, argv);