Browse Source

fix: open map check in service and player pos saved

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

14
maps/scene.cub

@ -3,28 +3,28 @@ EA ./textures/colorstone.xpm
SO ./textures/wood.xpm
WE ./textures/wood.xpm
F 147, 159, 153
C 219, 213, 213
F 147, 159,153
C 219,213,213
11110000
100100000
100111110
100000000
100100000
11111 11111 100100000
10001 1000111110011111111111
10001 1000000000000000000001
10001 1000000000000000000001
10000 1000111101111111100000
10001 1000111101111111100001
10001 10001 101000000100001
10001 10001 101111111100001
10001101110001 100000000000001
10001111110001 100000000000001
10000000000001 111110111100001
10000000000001 10111100001
00000E00000001 10000000001
10000E00000001 10000000001
10000000000001 10000000001
10111111111111 11111111111
100000001 10000000001
1111110011111101111110000000001
1111110011111111111110000000001
10000000100010000000000000000111
10000000000000000000000000000101
11111111110000000001111111111101

11
sources/main.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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])
{
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')
draw_square(env, vec, 24, 10420483);
else
draw_square(env, vec, 24, 255);
draw_square(env, vec, 6, 10420483);
vec.x++;
}
vec.y++;
}
draw_square(env, env->playerPos, 6, 255);
}
int main(int argc, char **argv)
@ -82,6 +81,8 @@ int main(int argc, char **argv)
if (argc != 2)
return (EXIT_FAILURE);
env = parse_envFile(argv[1]);
if (!env)
return (EXIT_FAILURE);
if (DEBUG)
{
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> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
void find_player(t_env *env)
int find_player(t_env *env)
{
char **map;
int x;
@ -160,12 +160,14 @@ void find_player(t_env *env)
env->playerPos.x = x;
env->playerPos.y = y;
env->yaw = cell;
return ;
map[y][x] = '0';
return (1);
}
x++;
}
y++;
}
return (0);
}
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));
if (checked[y * env->wide + x])
return (0);
else if (env->map[y][x] == '1')
checked[y * env->wide + x] = 1;
if (env->map[y][x] == '1')
return (0);
else if (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);
else
ret->map = create_map_array(e_map, ret->wide, ret->deep);
find_player(ret);
if (is_in_open_room(ret, ret->playerPos.x, ret->playerPos.y) && cleanup_datas(ret)) //add map cleanup in cleanup_datas
if ((!find_player(ret) || is_in_open_room(ret, ret->playerPos.x, ret->playerPos.y))
&& cleanup_datas(ret)) //add map cleanup in cleanup_datas
{
printf("Error: You are using an open map.");
return (NULL);
}
return (ret);
}

Loading…
Cancel
Save