Browse Source

fixed ugly minimap

master
nicolas-arnaud 2 years ago
parent
commit
1860d36b25
  1. 2
      includes/cub3d.h
  2. 14
      src/parsing/parsing.c
  3. 6
      src/render/minimap.c
  4. 13
      src/render/render.c

2
includes/cub3d.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */ /* Created: 2022/05/21 19:24:12 by narnaud #+# #+# */
/* Updated: 2022/11/21 18:55:22 by narnaud ### ########.fr */ /* Updated: 2022/11/21 19:41:26 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

14
src/parsing/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/11/21 19:00:21 by narnaud ### ########.fr */ /* Updated: 2022/11/21 19:43:41 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -75,11 +75,9 @@ t_slist *read_map_line(t_env *env, char *line)
ret = malloc(sizeof(t_slist)); ret = malloc(sizeof(t_slist));
i = 0; i = 0;
map_y = malloc((ft_strlen(line)) * sizeof(char)); map_y = malloc((ft_strlen(line)) * sizeof(char));
while (*line) while (*line && *line != '\n')
{ {
if (*line == '\n') if (!ft_isspace(*line))
break ;
else if (!ft_isspace(*line))
map_y[i] = *line; map_y[i] = *line;
else else
map_y[i] = '0'; map_y[i] = '0';
@ -119,12 +117,12 @@ t_env *load_map(char *filename)
line = get_next_line(fd); line = get_next_line(fd);
while (line) while (line)
{ {
if (*line && *line != '\n' && progress > 6 && progress++) if ((*line == '1' || *line == '\t' || *line == ' ')
&& progress > 6 && progress++)
ft_slst_add_back(&e_map, read_map_line(env, line)); ft_slst_add_back(&e_map, read_map_line(env, line));
else if (*line != '#') else if (*line != '#')
register_settings(&progress, env, line); register_settings(&progress, env, line);
free(line); line = (free(line), get_next_line(fd));
line = get_next_line(fd);
} }
if (progress < 7 && cleanup_datas(env)) if (progress < 7 && cleanup_datas(env))
return (printf("Error\nYour map isn't valid.\n"), NULL); return (printf("Error\nYour map isn't valid.\n"), NULL);

6
src/render/minimap.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/23 08:14:08 by narnaud #+# #+# */ /* Created: 2022/08/23 08:14:08 by narnaud #+# #+# */
/* Updated: 2022/11/21 19:01:36 by narnaud ### ########.fr */ /* Updated: 2022/11/21 19:56:47 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,13 +27,11 @@ t_rect get_mm_cell(char type, t_vec pos, t_vec delta)
return ((t_rect){vec_mult(pos, delta), delta, color}); return ((t_rect){vec_mult(pos, delta), delta, color});
} }
void render_minimap(t_env *env, t_vec size) void render_minimap(t_env *env, t_vec delt)
{ {
char **map; char **map;
t_vec pos; t_vec pos;
t_vec delt;
vec_set(&delt, size.x / env->wide, size.y / env->deep);
pos.y = 0; pos.y = 0;
map = env->map; map = env->map;
while (map[pos.y]) while (map[pos.y])

13
src/render/render.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */ /* Created: 2022/05/31 09:33:02 by narnaud #+# #+# */
/* Updated: 2022/11/21 19:04:16 by narnaud ### ########.fr */ /* Updated: 2022/11/21 20:04:25 by narnaud ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -88,9 +88,18 @@ void render_view(t_env *env)
void render(t_env *env) void render(t_env *env)
{ {
int delt;
ft_bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int)); ft_bzero(env->buffer, WIN_Y_SZ * WIN_X_SZ * sizeof(int));
render_view(env); render_view(env);
if (env->minimap) if (env->minimap)
render_minimap(env, (t_vec){WIN_X_SZ / 3, WIN_Y_SZ / 3}); {
delt = WIN_X_SZ / (env->wide * 2);
if (env->deep > WIN_Y_SZ / 2)
delt /= 2 * env->deep / WIN_Y_SZ;
if (env->wide > WIN_X_SZ / 2)
delt /= 2 * env->wide / WIN_X_SZ;
render_minimap(env, (t_vec){delt, delt});
}
mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0); mlx_put_image_to_window(env->mlx, env->win, env->img, 0, 0);
} }

Loading…
Cancel
Save