aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pong.c36
1 files changed, 36 insertions, 0 deletions
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) {