summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ball.c6
-rw-r--r--src/ball.h1
-rw-r--r--src/game.c17
-rw-r--r--src/paddle.c34
-rw-r--r--src/paddle.h1
5 files changed, 49 insertions, 10 deletions
diff --git a/src/ball.c b/src/ball.c
index e816057..c9ec8f1 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -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;
diff --git a/src/ball.h b/src/ball.h
index 6090c8e..7ba103f 100644
--- a/src/ball.h
+++ b/src/ball.h
@@ -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);
diff --git a/src/game.c b/src/game.c
index c12d731..b496708 100644
--- a/src/game.c
+++ b/src/game.c
@@ -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);