back to scratko.xyz
aboutsummaryrefslogtreecommitdiff
path: root/field.c
diff options
context:
space:
mode:
Diffstat (limited to 'field.c')
-rw-r--r--field.c28
1 files changed, 24 insertions, 4 deletions
diff --git a/field.c b/field.c
index a795f8e..add43d1 100644
--- a/field.c
+++ b/field.c
@@ -17,7 +17,7 @@ static const char field_sample[field_height][field_width] = {
{"/1....2//1..1//1..1//2....1/"},
{"//////.///// // /////.//////"},
{" /.///// // /////./ "},
- {" /.//1 1//./ "},
+ {" /.//1 y y 1//./ "},
{" /.// ///##/// //./ "},
{"//////.// / /2 2//////"},
{" 3 2/ / //2 "},
@@ -27,7 +27,7 @@ static const char field_sample[field_height][field_width] = {
{"/1....3..2..1//1..2..3....1/"},
{"/.////./////.//./////.////./"},
{"/.////./////.//./////.////./"},
- {"/1.1//2..2..2..2..2..2//1.1/"},
+ {"/1.1//2..2..y..y..2..2//1.1/"},
{"///.//.//.////////.//.//.///"},
{"///.//.//.////////.//.//.///"},
{"/1.2..1//1..1//1..1//1..2.1/"},
@@ -128,6 +128,7 @@ void clear_or_revert_symbol(game_space field, struct coordinates position,
case one_path:
case two_paths:
case three_paths:
+ case yellow_block:
if(field_has_coin(y, x))
queue_consists_point(eaten_coins, position) ?
addch(' ') : addch('.');
@@ -165,17 +166,26 @@ enum intersection_type get_intersection(const game_space field,
return two_paths;
case three_paths:
return three_paths;
+ case yellow_block:
+ return yellow_block;
default:
return direct_path;
}
}
+/*
+ * last conditions x-1 == left_outside_tunnel_x and
+ * 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 found_paths;
- found_paths.left = field[y][x-1] != '/' && field[y][x-1] != '#' ? 1 : 0;
- found_paths.right = field[y][x+1] != '/' && field[y][x+1] != '#' ? 1 : 0;
+ found_paths.left = (field[y][x-1] != '/' && field[y][x-1] != '#') ||
+ x-1 == left_outside_tunnel_x ? 1 : 0;
+ found_paths.right = (field[y][x+1] != '/' && field[y][x+1] != '#') ||
+ x+1 == right_outside_tunnel_x ? 1 : 0;
found_paths.up = field[y-1][x] != '/' && field[y-1][x] != '#' ? 1 : 0;
found_paths.down = field[y+1][x] != '/' && field[y+1][x] != '#' ? 1 : 0;
return found_paths;
@@ -186,3 +196,13 @@ int is_obstacle(const game_space field, int x, int y)
int symbol = field[y][x];
return symbol == door || symbol == block;
}
+
+void change_point_if_outside_tunnel(struct coordinates *point)
+{
+ if(point->x == left_outside_tunnel_x) {
+ point->x = right_outside_tunnel_x - 1;
+ return;
+ }
+ if(point->x == right_outside_tunnel_x)
+ point->x = left_outside_tunnel_x + 1;
+}