From 194f71c150eb9ee696acca17176092e8b0ce6e4f Mon Sep 17 00:00:00 2001 From: scratko Date: Tue, 16 Apr 2024 02:37:12 +0300 Subject: Scoring system Pacman's starting position doesn't contain a coin. Fixed an error in field_has_energizer(). The field prints the number of pacman lives and the score. All coin checks are moved to the field.c file. Restart is replaced by initialization of starting parameters. The final stage contains the game results screens. Queue clearing is combined with field clearing. Get_out_stage moved to struct mode_type. --- pac.c | 51 +++++---------------------------------------------- 1 file changed, 5 insertions(+), 46 deletions(-) (limited to 'pac.c') diff --git a/pac.c b/pac.c index 97c3833..c3fcbb7 100644 --- a/pac.c +++ b/pac.c @@ -5,7 +5,7 @@ void initialize_pac(struct pacman *pac) { pac->lives = max_live; - pac->coins_eaten = 0; + pac->score = 0; pac->position.y = pac_y; pac->position.x = pac_x; pac->direction = none; @@ -33,27 +33,6 @@ static enum movement_direction get_matching_for_directions(game_space field, } -#if 0 -void check_remaining_direction(game_space field, struct pacman *pac, - enum movement_direction *stored_direction) -{ - enum movement_direction temp_direction; - struct free_directions free_path = - find_free_directions(field, pac->position.x, pac->position.y); - enum movement_direction current_direction = - stored_direction ? *stored_direction : pac->direction; - temp_direction = get_correct_path(pac, free_path, current_direction); - if(temp_direction != none) - pac->direction = temp_direction; - else { - current_direction = pac->direction; - pac->direction = get_correct_path(pac, free_path, current_direction); - } - if(stored_direction) - *stored_direction = none; -} -#endif - void check_remaining_direction(game_space field, struct pacman *pac, enum movement_direction *stored_direction) { @@ -121,30 +100,9 @@ void change_pac_direction(game_space field, struct pacman *pac, int key, check_remaining_direction_after_pressed_key(field, pac); } -static int is_coin_symbol(int symbol) -{ - return - symbol == coin || symbol == energizer || symbol == one_path || - symbol == two_paths || symbol == three_paths; -} - -static int check_coin(game_space field, struct coordinates position, - struct queue *eaten_coins) -{ - int x, y; - x = position.x; - y = position.y; - return - is_coin_symbol(field[y][x]) && field_has_coin(x, y) && - !queue_consists_point(eaten_coins, position); -} - static void eat_energizer(game_space field, struct pacman *pac) { - int x, y; - x = pac->position.x; - y = pac->position.y; - if(field[y][x] == energizer) { + if(field_has_energizer(field, pac->position.x, pac->position.y)) { pac->is_energizer_eaten = 1; clear_energizer(field, pac->position); } @@ -170,9 +128,9 @@ void make_pac_move(game_space field, struct pacman *pac, default: return; } - if(check_coin(field, pac->position, eaten_coins)) { + if(check_coin_for_pac(field, pac->position, eaten_coins)) { queue_push(eaten_coins, &pac->position); - ++pac->coins_eaten; + ++pac->score; } change_point_if_outside_tunnel(&pac->position); eat_energizer(field, pac); @@ -181,6 +139,7 @@ void make_pac_move(game_space field, struct pacman *pac, void catch_pac(struct pacman *pac) { --pac->lives; + erase_life(pac->lives); if(pac->lives >= 1) { pac->position.y = pac_y; pac->position.x = pac_x; -- cgit v1.2.3