From 26f368af2fa30a758be1216b086a040af135bd1b Mon Sep 17 00:00:00 2001 From: Atsutane Date: Tue, 5 May 2009 17:22:07 +0200 Subject: Added ball_launch(). --- src/pong.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/pong.c b/src/pong.c index 51a2031..b916a33 100644 --- a/src/pong.c +++ b/src/pong.c @@ -278,6 +278,42 @@ void ball_movement(struct game_data *gd) { } +/* Handles the launch when a player scored */ +void ball_launch(struct game_data *gd) { + int c; + struct player_data *p; + + if (gd == NULL) { + return; + } + + p = (gd->ball->x == 1) ? gd->p1 : gd->p2; + + p->y = gd->ball->y; + + /* Check if it's the turn of the player, + * if so, let him move his pad. + */ + if (p->x == 0) { + while ((c = getch()) != ' ') { + if ((c == KEY_UP) && + (p->y > gd->ball->y-2) && + (p->y < gd->ball->y+2)) { + p->y--; + } + else if ((c == KEY_DOWN) && + (p->y > gd->ball->y-2) && + (p->y < gd->ball->y+2)) { + p->y++; + } + } + } + else { + p->y += rand()%3 - 1; + } +} + + /* Controls the pad of p2 */ void p2_ai(struct game_data *gd) { if (gd == NULL) { -- cgit v1.2.3-70-g09d2