diff --git a/field.c b/field.c index bcaac00..acf0ddf 100644 --- a/field.c +++ b/field.c @@ -100,8 +100,12 @@ void redraw_field(FIELD* f) { void update_ballpos(FIELD* f) { for (int i = 0; i < f -> ball_count; i++) { BALL* b = f -> balls[i]; - wattrset(f -> win, COLOR_PAIR(7)); - mvwprintw(f -> win, b -> old_position.y, b -> old_position.x * 2, " "); + // clear old ball position if it's not on player + if (! is_on_player(f -> player, & b -> old_position)) { + wattrset(f -> win, COLOR_PAIR(7)); + mvwprintw(f -> win, b -> old_position.y, b -> old_position.x * 2, " "); + } + // draw ball at new position wattrset(f -> win, COLOR_PAIR(b -> color)); mvwprintw(f -> win, b -> position.y, b -> position.x * 2, " "); } diff --git a/game.c b/game.c index 09a37d4..6ebaa5b 100644 --- a/game.c +++ b/game.c @@ -33,6 +33,7 @@ void eat_ball(FIELD* field, int pos) { //add new ball add_ball(field, maxval > 4 ? 4 : maxval); + redraw_field(field); } void play_game(GAME_STATE* state) { @@ -72,7 +73,6 @@ void play_game(GAME_STATE* state) { player_tick = (player_tick + 1) % 3; move_balls(f); update_ballpos(f); - if (!player_tick) { move_player(f); update_playerpos(f); diff --git a/player.c b/player.c index d94025a..8e620a8 100644 --- a/player.c +++ b/player.c @@ -18,6 +18,8 @@ void init_player(PLAYER* player, int x, int y) { player -> length = 6; player -> head_ptr = player -> length - 1; player -> body = malloc(sizeof(POINT*) * player -> length); + + player -> old_tail = NULL; for (int i = 0; i < player -> length; i++) { POINT* pt = malloc(sizeof(POINT)); @@ -31,6 +33,8 @@ void destroy_player(PLAYER* player) { for (int i = 0; i < player -> length; i++) { free(player -> body[i]); } + if (player -> old_tail) + free(player -> old_tail); free(player -> body); free(player); }