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