back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/pac.c
diff options
context:
space:
mode:
Diffstat (limited to 'pac.c')
-rw-r--r--pac.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/pac.c b/pac.c
index 1fd4b73..241609b 100644
--- a/pac.c
+++ b/pac.c
@@ -1,10 +1,11 @@
#include "pac.h"
#include "ncurses.h"
+#include "queue.h"
void initialize_pac(struct pacman *pac)
{
pac->lives = max_live;
- pac->points_eaten = 0;
+ pac->coins_eaten = 0;
pac->position.y = pac_y;
pac->position.x = pac_x;
pac->direction = none;
@@ -120,23 +121,44 @@ void change_pac_direction(game_space field, struct pacman *pac, int key,
check_remaining_direction_after_pressed_key(field, pac);
}
-void make_pac_move(game_space field, struct pacman *pac)
+static int is_coin_symbol(int symbol)
{
- eat_or_revert_symbol(field, pac->position.y, pac->position.x, pac_char);
+ return
+ symbol == coin || 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);
+}
+
+void make_pac_move(game_space field, struct pacman *pac,
+ struct queue *eaten_coins)
+{
+ clear_or_revert_symbol(field, pac->position, pac_char, eaten_coins);
switch(pac->direction) {
case left:
--pac->position.x;
- return;
+ break;
case right:
++pac->position.x;
- return;
+ break;
case up:
--pac->position.y;
- return;
+ break;
case down:
++pac->position.y;
- return;
+ break;
default:
return;
}
+ if(check_coin(field, pac->position, eaten_coins))
+ queue_push(eaten_coins, &pac->position);
}