diff options
| author | Atsutane <atsutane@freethoughts.de> | 2009-05-06 17:05:52 +0200 |
|---|---|---|
| committer | Atsutane <atsutane@freethoughts.de> | 2009-05-06 17:05:52 +0200 |
| commit | 9f54dcc72eed38492a894495d5c7242763daa379 (patch) | |
| tree | c73a4312268b2522f4aeb571b2d2f94b8f8bb1ed /src/pong.c | |
| parent | d75d701780fb6050153ac522d83706753eadc653 (diff) | |
| download | pong-9f54dcc72eed38492a894495d5c7242763daa379.tar.gz pong-9f54dcc72eed38492a894495d5c7242763daa379.tar.bz2 | |
Added movement for player 1.
Diffstat (limited to 'src/pong.c')
| -rw-r--r-- | src/pong.c | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -358,7 +358,9 @@ void p2_ai(struct game_data *gd) { int game(void) { clock_t clocks, /* contains clock since the start of the program */ interval; - int p, r; + int p, /* Time for player input y/n? */ + player_input, + r; /* return value */ struct game_data *gd; /* contains all our data */ if ((gd = init_game_data()) == NULL) { @@ -393,6 +395,34 @@ int game(void) { * man 3 curs_getch * man 3 curs_inopts */ + mvaddch(gd->p1->y-2, 0, ' '); + mvaddch(gd->p1->y-1, 0, ' '); + mvaddch(gd->p1->y, 0, ' '); + mvaddch(gd->p1->y+1, 0, ' '); + mvaddch(gd->p1->y+2, 0, ' '); + + /* Correct the position if the size of + * the terminal was changed. + */ + while((gd->p1->y+2) > (gd->max_field_y-1)) { + gd->p1->y--; + } + + player_input = getch(); + if ((player_input == KEY_UP) && + ((gd->p1->y-2) > 0)) { + gd->p1->y--; + } + else if ((player_input == KEY_DOWN) && + ((gd->p1->y+2) < (gd->max_field_y-1))) { + gd->p1->y++; + } + + mvaddch(gd->p1->y-2, 0, '|'); + mvaddch(gd->p1->y-1, 0, '|'); + mvaddch(gd->p1->y, 0, '|'); + mvaddch(gd->p1->y+1, 0, '|'); + mvaddch(gd->p1->y+2, 0, '|'); p2_ai(gd); p=0; |
