From d97f66ef26c89c8bd805cdeafffa959c91ec278b Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 21 May 2013 17:50:37 -0400 Subject: Add (stationary and invisible) balls to the board. --- diff --git a/src/ball.c b/src/ball.c new file mode 100644 index 0000000..7484950 --- /dev/null +++ b/src/ball.c @@ -0,0 +1,19 @@ +#include + +#include "ball.h" + +struct ball * +new_ball(int x, int y) +{ + struct ball *b; + + b = malloc(sizeof(*b)); + if (b == NULL) { + return NULL; + } + + b->x = x; + b->y = y; + + return b; +} diff --git a/src/ball.h b/src/ball.h new file mode 100644 index 0000000..c2be172 --- /dev/null +++ b/src/ball.h @@ -0,0 +1,17 @@ +#ifndef BALL_H +#define BALL_H + +#include "board.h" + +static const int BALL_START_X_NORMAL = 40; +static const int BALL_START_Y_NORMAL = 12; + +struct ball { + int x; + int y; + struct ball *next; +}; + +struct ball *new_ball(int x, int y); + +#endif diff --git a/src/game.c b/src/game.c index 9f7cebd..a5ae342 100644 --- a/src/game.c +++ b/src/game.c @@ -12,7 +12,7 @@ static void update(struct game *g); static void draw(struct game *g); struct game * -new_game(void) +new_game(char balls) { struct game *g; @@ -23,6 +23,8 @@ new_game(void) g->players[0] = new_player(0); g->players[1] = new_player(1); + g->min_balls = balls; + g->cur_balls = 0; return g; } @@ -91,10 +93,19 @@ input(struct game *g) static void update(struct game *g) { + struct ball *b; + update_paddle(&g->players[0]->paddle_h); update_paddle(&g->players[0]->paddle_v); update_paddle(&g->players[1]->paddle_h); update_paddle(&g->players[1]->paddle_v); + + while (g->cur_balls < g->min_balls) { + b = new_ball(BALL_START_X_NORMAL, BALL_START_Y_NORMAL); + b->next = g->balls_head; + g->balls_head = b; + ++g->cur_balls; + } } static void diff --git a/src/game.h b/src/game.h index 9a0f096..25d509b 100644 --- a/src/game.h +++ b/src/game.h @@ -2,13 +2,17 @@ #define GAME_H #include "player.h" +#include "ball.h" struct game { struct player *players[2]; char running; + char min_balls; + char cur_balls; + struct ball *balls_head; }; -struct game *new_game(void); +struct game *new_game(char balls); void free_game(struct game *g); void run_game(struct game *g); diff --git a/src/local.mk b/src/local.mk index 3f3338d..778f34c 100644 --- a/src/local.mk +++ b/src/local.mk @@ -2,4 +2,5 @@ src_SOURCES = \ src/main.c \ src/game.c \ src/player.c \ - src/paddle.c + src/paddle.c \ + src/ball.c diff --git a/src/main.c b/src/main.c index 408f47b..1034b2a 100644 --- a/src/main.c +++ b/src/main.c @@ -11,7 +11,7 @@ main(void) struct game *g; init_curses(); - g = new_game(); + g = new_game(1); run_game(g); -- cgit v0.9.1