fixed some bugs
parent
4b16aabf91
commit
beb46efaea
8
field.c
8
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, " ");
|
||||
}
|
||||
|
|
2
game.c
2
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);
|
||||
|
|
4
player.c
4
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue