static inline void updateball(ball *b){ eraseball(b); b->y+=b->direction_y; b->x+=b->direction_x; }
int playgame(short control) { struct player p1 = {P1_Y, P1_X, 1, 0, 0, 35, 0}; struct player p2 = {P2_Y, P2_X, 0, 0, 0, 40, 0}; struct ball b = {B_Y, B_X, B_SPEED, B_DIRY, 1, 0}; short gameover = 0; short bcounter = 0; short bbcounter = 0; short pcounter = 0; int c; while (!gameover) { /* Draw everything and pause for one tick. */ drawpaddle(p1); drawpaddle(p2); drawnet(); drawball(b); refresh(); napms(SPEED); /* Get input. */ control = controlpaddle(&p1, b, control); if (!control) break; controlpaddle(&p2, b, 0); if (pcounter++ == P_SPEED) { updatepaddle(&p1); updatepaddle(&p2); pcounter = 0; } if (bcounter++ == b.speed) { eraseball(b); if (updateball(&b, &p1, &p2) == 0) { bcounter = 0; if (bbcounter++ == 200 && b.speed > 1) --b.speed; } else { bcounter = 0; bbcounter = 0; p1.y = P1_Y; p1.x = P1_X; p1.dir = 0; p2.y = P2_Y; p2.x = P2_X; p2.dir = 0; clear(); drawpaddle(p1); drawpaddle(p2); drawnet(); drawball(b); refresh(); /* Wait for space or a mouse click */ do { c = getch(); napms(10); if (c == 'q') return 0; } while ((c != ' ') && (c != KEY_MOUSE)); if (p1.score == 21) { return 1; } else if (p2.score == 21) { return 2; } } } napms(SPEED); } return 0; }