Browse Source

fix: open map check in service and player pos saved

master
narnaud 3 years ago
parent
commit
5d7669ebaf
  1. 10
      maps/scene.cub
  2. 11
      sources/main.c
  3. 18
      sources/parsing.c

10
maps/scene.cub

@ -9,22 +9,22 @@ C 219, 213, 213
11110000 11110000
100100000 100100000
100111110 100111110
100000000 100100000
11111 11111 100100000 11111 11111 100100000
10001 1000111110011111111111 10001 1000111110011111111111
10001 1000000000000000000001 10001 1000000000000000000001
10001 1000000000000000000001 10001 1000000000000000000001
10000 1000111101111111100000 10001 1000111101111111100001
10001 10001 101000000100001 10001 10001 101000000100001
10001 10001 101111111100001 10001 10001 101111111100001
10001101110001 100000000000001 10001111110001 100000000000001
10000000000001 111110111100001 10000000000001 111110111100001
10000000000001 10111100001 10000000000001 10111100001
00000E00000001 10000000001 10000E00000001 10000000001
10000000000001 10000000001 10000000000001 10000000001
10111111111111 11111111111 10111111111111 11111111111
100000001 10000000001 100000001 10000000001
1111110011111101111110000000001 1111110011111111111110000000001
10000000100010000000000000000111 10000000100010000000000000000111
10000000000000000000000000000101 10000000000000000000000000000101
11111111110000000001111111111101 11111111110000000001111111111101

11
sources/main.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */ /* Created: 2022/05/21 19:22:50 by narnaud #+# #+# */
/* Updated: 2022/05/30 16:50:21 by narnaud ### ########.fr */ /* Updated: 2022/05/31 07:54:29 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -63,15 +63,14 @@ void render_minimap(t_env *env)
while (map[vec.y][vec.x]) while (map[vec.y][vec.x])
{ {
if (map[vec.y][vec.x] == '0') if (map[vec.y][vec.x] == '0')
draw_square(env, vec, 24, 39424); draw_square(env, vec, 6, 39424);
else if (map[vec.y][vec.x] == '1') else if (map[vec.y][vec.x] == '1')
draw_square(env, vec, 24, 10420483); draw_square(env, vec, 6, 10420483);
else
draw_square(env, vec, 24, 255);
vec.x++; vec.x++;
} }
vec.y++; vec.y++;
} }
draw_square(env, env->playerPos, 6, 255);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -82,6 +81,8 @@ int main(int argc, char **argv)
if (argc != 2) if (argc != 2)
return (EXIT_FAILURE); return (EXIT_FAILURE);
env = parse_envFile(argv[1]); env = parse_envFile(argv[1]);
if (!env)
return (EXIT_FAILURE);
if (DEBUG) if (DEBUG)
{ {
printf("\e[1;32m========> WALLS <========\e[0m\nNorth: %s\nSouth: %s\nWest: %s\nEast: %s\n",\ printf("\e[1;32m========> WALLS <========\e[0m\nNorth: %s\nSouth: %s\nWest: %s\nEast: %s\n",\

18
sources/parsing.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */ /* Created: 2022/05/23 17:20:29 by narnaud #+# #+# */
/* Updated: 2022/05/30 18:07:33 by narnaud ### ########.fr */ /* Updated: 2022/05/31 07:56:35 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -139,7 +139,7 @@ char **create_map_array(t_slist *e_lst, int wide, int deep)
return (ret); return (ret);
} }
void find_player(t_env *env) int find_player(t_env *env)
{ {
char **map; char **map;
int x; int x;
@ -160,12 +160,14 @@ void find_player(t_env *env)
env->playerPos.x = x; env->playerPos.x = x;
env->playerPos.y = y; env->playerPos.y = y;
env->yaw = cell; env->yaw = cell;
return ; map[y][x] = '0';
return (1);
} }
x++; x++;
} }
y++; y++;
} }
return (0);
} }
int is_in_open_room(t_env *env, int x, int y) int is_in_open_room(t_env *env, int x, int y)
@ -178,7 +180,8 @@ int is_in_open_room(t_env *env, int x, int y)
checked = ft_calloc(env->deep * env->wide + 1, sizeof(char)); checked = ft_calloc(env->deep * env->wide + 1, sizeof(char));
if (checked[y * env->wide + x]) if (checked[y * env->wide + x])
return (0); return (0);
else if (env->map[y][x] == '1') checked[y * env->wide + x] = 1;
if (env->map[y][x] == '1')
return (0); return (0);
else if (is_in_open_room(env, x + 1, y) else if (is_in_open_room(env, x + 1, y)
|| is_in_open_room(env, x - 1, y) || is_in_open_room(env, x - 1, y)
@ -217,8 +220,11 @@ t_env *parse_envFile(char *filename)
return (NULL); return (NULL);
else else
ret->map = create_map_array(e_map, ret->wide, ret->deep); ret->map = create_map_array(e_map, ret->wide, ret->deep);
find_player(ret); if ((!find_player(ret) || is_in_open_room(ret, ret->playerPos.x, ret->playerPos.y))
if (is_in_open_room(ret, ret->playerPos.x, ret->playerPos.y) && cleanup_datas(ret)) //add map cleanup in cleanup_datas && cleanup_datas(ret)) //add map cleanup in cleanup_datas
{
printf("Error: You are using an open map.");
return (NULL); return (NULL);
}
return (ret); return (ret);
} }

Loading…
Cancel
Save