From 04a6703fd66a7d34b2556a9c203c4dada3baca38 Mon Sep 17 00:00:00 2001 From: scratko Date: Fri, 12 Apr 2024 03:17:46 +0300 Subject: Added behavior modes Reverse direction Random direction --- pac.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'pac.c') diff --git a/pac.c b/pac.c index ed929ae..dcd3b40 100644 --- a/pac.c +++ b/pac.c @@ -9,6 +9,7 @@ void initialize_pac(struct pacman *pac) pac->position.y = pac_y; pac->position.x = pac_x; pac->direction = none; + pac->is_energizer_eaten = 0; } static enum movement_direction get_matching_for_directions(game_space field, @@ -124,8 +125,8 @@ void change_pac_direction(game_space field, struct pacman *pac, int key, static int is_coin_symbol(int symbol) { return - symbol == coin || symbol == one_path || symbol == two_paths || - symbol == three_paths; + symbol == coin || symbol == energizer || symbol == one_path || + symbol == two_paths || symbol == three_paths; } static int check_coin(game_space field, struct coordinates position, @@ -139,6 +140,15 @@ static int check_coin(game_space field, struct coordinates position, !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) + pac->is_energizer_eaten = 1; +} + void make_pac_move(game_space field, struct pacman *pac, struct queue *eaten_coins) { @@ -159,7 +169,10 @@ void make_pac_move(game_space field, struct pacman *pac, default: return; } - if(check_coin(field, pac->position, eaten_coins)) + if(check_coin(field, pac->position, eaten_coins)) { queue_push(eaten_coins, &pac->position); + ++pac->coins_eaten; + } change_point_if_outside_tunnel(&pac->position); + eat_energizer(field, pac); } -- cgit v1.2.3