back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/pac.c
diff options
context:
space:
mode:
Diffstat (limited to 'pac.c')
-rw-r--r--pac.c19
1 files changed, 16 insertions, 3 deletions
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);
}