aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAtsutane <atsutane@freethoughts.de>2009-05-06 17:05:52 +0200
committerAtsutane <atsutane@freethoughts.de>2009-05-06 17:05:52 +0200
commit9f54dcc72eed38492a894495d5c7242763daa379 (patch)
treec73a4312268b2522f4aeb571b2d2f94b8f8bb1ed /src
parentd75d701780fb6050153ac522d83706753eadc653 (diff)
downloadpong-9f54dcc72eed38492a894495d5c7242763daa379.tar.gz
pong-9f54dcc72eed38492a894495d5c7242763daa379.tar.bz2
Added movement for player 1.
Diffstat (limited to 'src')
-rw-r--r--src/pong.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/pong.c b/src/pong.c
index 8981c14..c185d85 100644
--- a/src/pong.c
+++ b/src/pong.c
@@ -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;