summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.c65
-rw-r--r--src/paddle.c32
-rw-r--r--src/paddle.h2
-rw-r--r--src/player.c9
-rw-r--r--src/player.h2
5 files changed, 49 insertions, 61 deletions
diff --git a/src/game.c b/src/game.c
index 8342166..bbd4cf5 100644
--- a/src/game.c
+++ b/src/game.c
@@ -6,7 +6,6 @@
#include "player.h"
#include "paddle.h"
-static void draw_paddles(struct game *g);
static void wait(struct game *g);
static void input(struct game *g);
static void update(struct game *g);
@@ -22,8 +21,8 @@ new_game(void)
return NULL;
}
- g->players[0] = new_player();
- g->players[1] = new_player();
+ g->players[0] = new_player(0);
+ g->players[1] = new_player(1);
return g;
}
@@ -93,60 +92,8 @@ update(struct game *g)
static void
draw(struct game *g)
{
- draw_paddles(g);
-}
-
-static void
-draw_paddles(struct game *g)
-{
- int off;
- int pos;
-
- /* Player 1 horizontal paddle */
- for (pos = 0; pos < 79; ++pos) {
- mvprintw(23, pos, " ");
- }
- off = g->players[0]->paddle_h.pos;
- off -= g->players[0]->paddle_h.size / 2;
- for (pos = 0; pos < g->players[0]->paddle_h.size; ++pos) {
- attr_on(WA_REVERSE, NULL);
- mvprintw(23, off + pos, " ");
- attr_off(WA_REVERSE, NULL);
- }
-
- /* Player 1 vertical paddle */
- for (pos = 0; pos < 24; ++pos) {
- mvprintw(pos, 2, " ");
- }
- off = g->players[0]->paddle_v.pos;
- off -= g->players[0]->paddle_v.size / 2;
- for (pos = 0; pos < g->players[0]->paddle_v.size; ++pos) {
- attr_on(WA_REVERSE, NULL);
- mvprintw(off + pos, 2, " ");
- attr_off(WA_REVERSE, NULL);
- }
-
- /* Player 2 horizontal paddle */
- for (pos = 0; pos < 79; ++pos) {
- mvprintw(1, pos, " ");
- }
- off = g->players[1]->paddle_h.pos;
- off -= g->players[1]->paddle_h.size / 2;
- for (pos = 0; pos < g->players[1]->paddle_h.size; ++pos) {
- attr_on(WA_REVERSE, NULL);
- mvprintw(1, off + pos, " ");
- attr_off(WA_REVERSE, NULL);
- }
-
- /* Player 2 vertical paddle */
- for (pos = 0; pos < 24; ++pos) {
- mvprintw(pos, 77, " ");
- }
- off = g->players[1]->paddle_v.pos;
- off -= g->players[1]->paddle_v.size / 2;
- for (pos = 0; pos < g->players[1]->paddle_v.size; ++pos) {
- attr_on(WA_REVERSE, NULL);
- mvprintw(off + pos, 77, " ");
- attr_off(WA_REVERSE, NULL);
- }
+ draw_paddle(&g->players[0]->paddle_h);
+ draw_paddle(&g->players[0]->paddle_v);
+ draw_paddle(&g->players[1]->paddle_h);
+ draw_paddle(&g->players[1]->paddle_v);
}
diff --git a/src/paddle.c b/src/paddle.c
index 57cdbb5..49f03c3 100644
--- a/src/paddle.c
+++ b/src/paddle.c
@@ -1,3 +1,5 @@
+#include <curses.h>
+
#include "paddle.h"
void
@@ -14,3 +16,33 @@ update_paddle(struct paddle *pad)
if (pad->pos < pad->size / 2 + 2) pad->pos = pad->size / 2 + 2;
if (pad->pos > max - pad->size / 2) pad->pos = max - pad->size / 2;
}
+
+void
+draw_paddle(struct paddle *pad)
+{
+ int off;
+ int pos;
+
+ off = pad->pos;
+ off -= pad->size / 2;
+
+ if (pad->type == PADDLE_TYPE_H) {
+ for (pos = 0; pos < 79; ++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 < 24; ++pos) {
+ mvprintw(pos, pad->track, " ");
+ }
+ for (pos = 0; pos < pad->size; ++pos) {
+ attr_on(WA_REVERSE, NULL);
+ mvprintw(off + pos, pad->track, " ");
+ attr_off(WA_REVERSE, NULL);
+ }
+ }
+}
diff --git a/src/paddle.h b/src/paddle.h
index 46891ba..714eca6 100644
--- a/src/paddle.h
+++ b/src/paddle.h
@@ -18,8 +18,10 @@ struct paddle {
int speed;
int dir;
int type;
+ int track;
};
void update_paddle(struct paddle *pad);
+void draw_paddle(struct paddle *pad);
#endif
diff --git a/src/player.c b/src/player.c
index ad0166a..844424f 100644
--- a/src/player.c
+++ b/src/player.c
@@ -4,7 +4,7 @@
#include "paddle.h"
struct player *
-new_player(void)
+new_player(int id)
{
struct player *p;
@@ -24,6 +24,13 @@ new_player(void)
p->paddle_v.dir = 0;
p->paddle_h.type = PADDLE_TYPE_H;
p->paddle_v.type = PADDLE_TYPE_V;
+ if (id == 0) {
+ p->paddle_h.track = 23;
+ p->paddle_v.track = 2;
+ } else {
+ p->paddle_h.track = 1;
+ p->paddle_v.track = 77;
+ }
return p;
}
diff --git a/src/player.h b/src/player.h
index e78cbdc..5a4cbac 100644
--- a/src/player.h
+++ b/src/player.h
@@ -9,7 +9,7 @@ struct player {
struct paddle paddle_v;
};
-struct player *new_player(void);
+struct player *new_player(int id);
void free_player(struct player *p);
#endif