From ef3844bf2128fa82f20c5995d1fca66fadba2ce3 Mon Sep 17 00:00:00 2001 From: scratko Date: Wed, 17 Apr 2024 17:00:48 +0300 Subject: Added colors Changed the number of pacman's lives. Fixed clear_or_revert_symbol(). Target hit display. Changed ghost initialization. Clearing ghost positions is moved to the function. Added flag in struct ghost_type (reached_pacman). Changed catching stage. Now eating an energizer resets the counter. --- ghosts.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'ghosts.c') diff --git a/ghosts.c b/ghosts.c index d558ba5..5c60200 100644 --- a/ghosts.c +++ b/ghosts.c @@ -17,13 +17,8 @@ void initialize_ghost(struct ghost_type *ghost, enum ghost_color color) ghost->home_position.y = red_home_y; ghost->home_position.x = red_home_x; ghost->color = red; - ghost->frightened_status = 0; - ghost->direction = none; ghost->prison_params.position.x = red_prison_x; ghost->prison_params.position.y = red_prison_y; - ghost->prison_params.prison_counter = 0; - ghost->prison_params.active = 0; - ghost->capture_info.status = 0; break; case pink: ghost->position.y = pink_y; @@ -31,13 +26,8 @@ void initialize_ghost(struct ghost_type *ghost, enum ghost_color color) ghost->home_position.y = pink_home_y; ghost->home_position.x = pink_home_x; ghost->color = pink; - ghost->frightened_status = 0; - ghost->direction = none; ghost->prison_params.position.x = pink_prison_x; ghost->prison_params.position.y = pink_prison_y; - ghost->prison_params.prison_counter = 0; - ghost->prison_params.active = 0; - ghost->capture_info.status = 0; break; case blue: ghost->position.y = blue_y; @@ -45,13 +35,8 @@ void initialize_ghost(struct ghost_type *ghost, enum ghost_color color) ghost->home_position.y = blue_home_y; ghost->home_position.x = blue_home_x; ghost->color = blue; - ghost->frightened_status = 0; - ghost->direction = none; ghost->prison_params.position.x = blue_prison_x; ghost->prison_params.position.y = blue_prison_y; - ghost->prison_params.prison_counter = 0; - ghost->prison_params.active = 0; - ghost->capture_info.status = 0; break; case orange: ghost->position.y = orange_y; @@ -59,15 +44,16 @@ void initialize_ghost(struct ghost_type *ghost, enum ghost_color color) ghost->home_position.y = orange_home_y; ghost->home_position.x = orange_home_x; ghost->color = orange; - ghost->frightened_status = 0; - ghost->direction = none; ghost->prison_params.position.x = orange_prison_x; ghost->prison_params.position.y = orange_prison_y; + break; + } + ghost->frightened_status = 0; + ghost->direction = none; ghost->prison_params.prison_counter = 0; ghost->prison_params.active = 0; ghost->capture_info.status = 0; - break; - } + ghost->reached_pacman = 0; } void pull_out_ghosts(int *get_out_stage, @@ -114,12 +100,11 @@ static void change_position(struct ghost_type *ghost, change_point_if_outside_tunnel(&ghost->position); } -void make_ghost_moves(game_space field, - struct ghost_type *red_ghost, - struct ghost_type *pink_ghost, - struct ghost_type *blue_ghost, - struct ghost_type *orange_ghost, - struct queue *eaten_coins) +void clear_ghost_positions(game_space field, const struct queue *eaten_coins, + const struct ghost_type *red_ghost, + const struct ghost_type *pink_ghost, + const struct ghost_type *blue_ghost, + const struct ghost_type *orange_ghost) { clear_or_revert_symbol(field, red_ghost->position, ghost_char, eaten_coins); clear_or_revert_symbol(field, pink_ghost->position, ghost_char, @@ -128,6 +113,17 @@ void make_ghost_moves(game_space field, eaten_coins); clear_or_revert_symbol(field, orange_ghost->position, ghost_char, eaten_coins); +} + +void make_ghost_moves(game_space field, + struct ghost_type *red_ghost, + struct ghost_type *pink_ghost, + struct ghost_type *blue_ghost, + struct ghost_type *orange_ghost, + struct queue *eaten_coins) +{ + clear_ghost_positions(field, eaten_coins, red_ghost, pink_ghost, blue_ghost, + orange_ghost); change_position(red_ghost, red_ghost->direction); change_position(pink_ghost, pink_ghost->direction); change_position(blue_ghost, blue_ghost->direction); -- cgit v1.2.3