diff options
author | P. J. McDermott <pjm@nac.net> | 2013-05-21 18:28:17 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-05-21 18:28:17 (EDT) |
commit | f40768e82a9f396526c30c0bda10388f4746fbea (patch) | |
tree | 196ff36cd9abcf12926b63c6817eb90a6a1569e5 | |
parent | 4e6e4ab53d3d43725f117c0dbf613b2bd9c7794c (diff) | |
download | cursespong-f40768e82a9f396526c30c0bda10388f4746fbea.zip cursespong-f40768e82a9f396526c30c0bda10388f4746fbea.tar.gz cursespong-f40768e82a9f396526c30c0bda10388f4746fbea.tar.bz2 |
Add board clearing functions.
-rw-r--r-- | src/ball.c | 6 | ||||
-rw-r--r-- | src/ball.h | 1 | ||||
-rw-r--r-- | src/game.c | 17 | ||||
-rw-r--r-- | src/paddle.c | 34 | ||||
-rw-r--r-- | src/paddle.h | 1 |
5 files changed, 49 insertions, 10 deletions
@@ -26,6 +26,12 @@ free_ball(struct ball *b) } void +clear_ball(struct ball *b) +{ + mvprintw(b->y, b->x, " "); +} + +void update_ball(struct ball *b) { ++b; @@ -14,6 +14,7 @@ struct ball { struct ball *new_ball(int x, int y); void free_ball(struct ball *b); +void clear_ball(struct ball *b); void update_ball(struct ball *b); void draw_ball(struct ball *b); @@ -8,6 +8,7 @@ static void wait(struct game *g); static void input(struct game *g); +static void clear_game(struct game *g); static void update(struct game *g); static void draw(struct game *g); @@ -45,6 +46,7 @@ run_game(struct game *g) while (g->running) { input(g); + clear_game(g); update(g); draw(g); wait(g); @@ -91,6 +93,21 @@ input(struct game *g) } static void +clear_game(struct game *g) +{ + struct ball *b; + + clear_paddle(&g->players[0]->paddle_h); + clear_paddle(&g->players[0]->paddle_v); + clear_paddle(&g->players[1]->paddle_h); + clear_paddle(&g->players[1]->paddle_v); + + for (b = g->balls_head; b != NULL; b = b->next) { + clear_ball(b); + } +} + +static void update(struct game *g) { struct ball *b; diff --git a/src/paddle.c b/src/paddle.c index 4bf90fa..0028892 100644 --- a/src/paddle.c +++ b/src/paddle.c @@ -22,7 +22,7 @@ update_paddle(struct paddle *pad) } void -draw_paddle(struct paddle *pad) +clear_paddle(struct paddle *pad) { int off; int pos; @@ -31,22 +31,36 @@ draw_paddle(struct paddle *pad) off -= pad->size / 2; if (pad->type == PADDLE_TYPE_H) { - for (pos = 0; pos < BOARD_WIDTH - 1; ++pos) { - mvprintw(pad->track, pos, " "); - } for (pos = 0; pos < pad->size; ++pos) { - attr_on(WA_REVERSE, NULL); mvprintw(pad->track, off + pos, " "); - attr_off(WA_REVERSE, NULL); } } else { - for (pos = 0; pos < BOARD_HEIGHT - 1; ++pos) { - mvprintw(pos, pad->track, " "); + for (pos = 0; pos < pad->size; ++pos) { + mvprintw(off + pos, pad->track, " "); } + } +} + +void +draw_paddle(struct paddle *pad) +{ + int off; + int pos; + + off = pad->pos; + off -= pad->size / 2; + + attr_on(WA_REVERSE, NULL); + + if (pad->type == PADDLE_TYPE_H) { + for (pos = 0; pos < pad->size; ++pos) { + mvprintw(pad->track, off + pos, " "); + } + } else { for (pos = 0; pos < pad->size; ++pos) { - attr_on(WA_REVERSE, NULL); mvprintw(off + pos, pad->track, " "); - attr_off(WA_REVERSE, NULL); } } + + attr_off(WA_REVERSE, NULL); } diff --git a/src/paddle.h b/src/paddle.h index 714eca6..8d885b0 100644 --- a/src/paddle.h +++ b/src/paddle.h @@ -21,6 +21,7 @@ struct paddle { int track; }; +void clear_paddle(struct paddle *pad); void update_paddle(struct paddle *pad); void draw_paddle(struct paddle *pad); |