back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--field.c42
-rw-r--r--field.h2
-rw-r--r--ghosts.c8
-rw-r--r--pac.c12
-rw-r--r--pacman.c11
5 files changed, 56 insertions, 19 deletions
diff --git a/field.c b/field.c
index 37a5be1..2dcd783 100644
--- a/field.c
+++ b/field.c
@@ -60,6 +60,16 @@ int field_has_coin(int x, int y)
(x == 17 && y == 9) || (x == 17 && y == 18));
}
+int field_has_energizer(const game_space field, int x, int y)
+{
+ return field[y][x] = energizer;
+}
+
+static int yellow_block_contains_coin(int x, int y)
+{
+ return (x == 12 && y == 22) || (x == 15 && y == 22);
+}
+
void print_field(game_space field)
{
int i;
@@ -73,7 +83,13 @@ void print_field(game_space field)
case one_path:
case two_paths:
case three_paths:
- if(field_has_coin(i, j))
+ if(field_has_coin(j, i))
+ addch('.');
+ else
+ addch(' ');
+ break;
+ case yellow_block:
+ if(yellow_block_contains_coin(j, i))
addch('.');
else
addch(' ');
@@ -117,7 +133,7 @@ void display_ghosts_on_field(struct ghost_type *red_ghost,
ghost_char);
}
-void clear_or_revert_symbol(game_space field, struct coordinates position,
+void clear_or_revert_symbol(const game_space field, struct coordinates position,
enum select_character character,
struct queue *eaten_coins)
{
@@ -131,8 +147,14 @@ void clear_or_revert_symbol(game_space field, struct coordinates position,
case one_path:
case two_paths:
case three_paths:
+ if(field_has_coin(x, y))
+ queue_consists_point(eaten_coins, position) ?
+ addch(' ') : addch('.');
+ else
+ addch(' ');
+ break;
case yellow_block:
- if(field_has_coin(y, x))
+ if(yellow_block_contains_coin(x, y))
queue_consists_point(eaten_coins, position) ?
addch(' ') : addch('.');
else
@@ -142,6 +164,8 @@ void clear_or_revert_symbol(game_space field, struct coordinates position,
addch('#');
break;
case energizer:
+ field_has_energizer(field, x, y) ? addch('*') : addch(' ');
+ break;
case coin:
queue_consists_point(eaten_coins, position) ?
addch(' ') : addch('.');
@@ -182,8 +206,8 @@ enum intersection_type get_intersection(const game_space field,
* x+1 == right_outside_tunnel_x are used by only pacman (while
* cheking remaining direction)
*/
-struct free_directions find_free_directions(const game_space field, int y,
- int x)
+struct free_directions find_free_directions(const game_space field, int x,
+ int y)
{
struct free_directions found_paths;
found_paths.left = (field[y][x-1] != '/' && field[y][x-1] != '#') ||
@@ -210,3 +234,11 @@ void change_point_if_outside_tunnel(struct coordinates *point)
if(point->x == right_outside_tunnel_x)
point->x = left_outside_tunnel_x + 1;
}
+
+void clear_energizer(game_space field, struct coordinates point)
+{
+ int x, y;
+ x = point.x;
+ y = point.y;
+ field[y][x] = ' ';
+}
diff --git a/field.h b/field.h
index 7eb4ba1..ecf8c9a 100644
--- a/field.h
+++ b/field.h
@@ -62,4 +62,6 @@ int field_has_coin(int x, int y);
void change_point_if_outside_tunnel(struct coordinates *point);
+void clear_energizer(game_space field, struct coordinates point);
+
#endif
diff --git a/ghosts.c b/ghosts.c
index ded74e7..f8edfa2 100644
--- a/ghosts.c
+++ b/ghosts.c
@@ -116,8 +116,8 @@ void make_ghost_moves(game_space field,
static void pave_only_way(game_space field, struct ghost_type *ghost)
{
- struct free_directions path = find_free_directions(field, ghost->position.y,
- ghost->position.x);
+ struct free_directions path = find_free_directions(field, ghost->position.x,
+ ghost->position.y);
enum movement_direction reverse_direction = ghost->direction;
reverse_direction ^= 1;
if(path.left && left != reverse_direction)
@@ -344,7 +344,7 @@ void compute_distance_between_points(game_space field,
initial_point = ghost->position;
min_distance = 0;
struct free_directions consider_paths =
- find_free_directions(field, initial_point.y, initial_point.x);
+ find_free_directions(field, initial_point.x, initial_point.y);
if(consider_paths.right && ghost_direction != left) {
changed_initial_point.x = initial_point.x + 1;
changed_initial_point.y = initial_point.y;
@@ -399,7 +399,7 @@ void random_redirect(game_space field, struct ghost_type *ghost)
{
enum movement_direction random_direction;
struct free_directions paths =
- find_free_directions(field, ghost->position.y, ghost->position.x);
+ find_free_directions(field, ghost->position.x, ghost->position.y);
random_direction = get_random_direction();
while(!is_equal_directions(random_direction, paths))
random_direction = get_random_direction();
diff --git a/pac.c b/pac.c
index dcd3b40..a3cae71 100644
--- a/pac.c
+++ b/pac.c
@@ -18,7 +18,7 @@ static enum movement_direction get_matching_for_directions(game_space field,
direction)
{
struct free_directions free_paths =
- find_free_directions(field, pac->position.y, pac->position.x);
+ find_free_directions(field, pac->position.x, pac->position.y);
switch(direction) {
case left:
return free_paths.left ? left : none;
@@ -40,7 +40,7 @@ void check_remaining_direction(game_space field, struct pacman *pac,
{
enum movement_direction temp_direction;
struct free_directions free_path =
- find_free_directions(field, pac->position.y, pac->position.x);
+ 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);
@@ -86,8 +86,8 @@ void change_pac_direction(game_space field, struct pacman *pac, int key,
{
enum state { no, yes } is_changed_direction;
is_changed_direction = no;
- struct free_directions path = find_free_directions(field, pac->position.y,
- pac->position.x);
+ struct free_directions path = find_free_directions(field, pac->position.x,
+ pac->position.y);
switch(key) {
case KEY_LEFT:
if(path.left) {
@@ -145,8 +145,10 @@ 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[y][x] == energizer) {
pac->is_energizer_eaten = 1;
+ clear_energizer(field, pac->position);
+ }
}
void make_pac_move(game_space field, struct pacman *pac,
diff --git a/pacman.c b/pacman.c
index f9b1278..f03941c 100644
--- a/pacman.c
+++ b/pacman.c
@@ -12,7 +12,7 @@ enum {
sleep_duration = 190000,
key_escape = 27,
count_get_out_moves = 6,
- chase_move_limit = 100,
+ chase_move_limit = 70,
scatter_move_limit = 35,
frightened_move_limit = 30,
phase_limit = 4
@@ -40,7 +40,8 @@ static void change_mode(struct mode_type *mode_params)
++mode_params->phase_number;
if(mode_params->phase_number == phase_limit)
mode_params->current_mode = chase;
- ++mode_params->reverse_direction;
+ if(mode_params->phase_number != phase_limit)
+ ++mode_params->reverse_direction;
}
break;
case scatter:
@@ -293,11 +294,11 @@ int main()
#if 1
move(0, 50);
if(mode_params.current_mode == chase)
- printw("CHASE");
+ printw("CHASE %d ", mode_params.chase_count);
else if(mode_params.current_mode == scatter)
- printw("SCATTER");
+ printw("SCATTER %d ", mode_params.scatter_count);
else if(mode_params.current_mode == frightened)
- printw("FRIGHTENED");
+ printw("FRIGHTENED %d ", mode_params.frightened_count);
refresh();
#endif
}