aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_warp_level.c
blob: cfacd819b3a724919d8045c82149fa3a8e204dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_warp_level.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/28 20:54:28 by rbousset          #+#    #+#             */
/*   Updated: 2020/02/28 20:54:29 by rbousset         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <mlx.h>

static void
	ft_del_map(t_map *ml)
{
	ft_memdel((void**)&ml->no_tex_path);
	ft_memdel((void**)&ml->so_tex_path);
	ft_memdel((void**)&ml->ea_tex_path);
	ft_memdel((void**)&ml->we_tex_path);
	ft_memdel((void**)&ml->sprite_path);
	ft_memdel((void**)&ml->nl_tex_path);
	ft_memdel((void**)&ml->nlevel_path);
	ft_memdel((void**)&ml->mapl);
	ft_free_words(ml->map);
	ft_memdel((void**)&ml);
}

static void
	ft_del_some(t_cub *cl)
{
	cl->plist->pos_x = 0;
	cl->plist->pos_y = 0;
	cl->plist->start_x = 0;
	cl->plist->start_y = 0;
	cl->plist->cam_x = 0;
	cl->plist->dir_x = -1;
	cl->plist->dir_y = 0;
	cl->plist->plane_x = 0;
	cl->plist->plane_y = 0.66666666;
	cl->f_rgb = ft_init_rgb();
	cl->c_rgb = ft_init_rgb();
	cl->rlist = ft_init_s_ray();
	mlx_destroy_image(cl->wlist->wlx, cl->tlist[0].img);
	mlx_destroy_image(cl->wlist->wlx, cl->tlist[1].img);
	mlx_destroy_image(cl->wlist->wlx, cl->tlist[2].img);
	mlx_destroy_image(cl->wlist->wlx, cl->tlist[3].img);
	mlx_destroy_image(cl->wlist->wlx, cl->tlist[4].img);
	mlx_destroy_image(cl->wlist->wlx, cl->tlist[5].img);
	cl->tlist[0].img = NULL;
	cl->tlist[1].img = NULL;
	cl->tlist[2].img = NULL;
	cl->tlist[3].img = NULL;
	cl->tlist[4].img = NULL;
	cl->tlist[5].img = NULL;
}

int8_t
	ft_warp_level(t_cub *cl)
{
	char	*next_path;

	if ((uint32_t)cl->plist->pos_x == cl->mlist->nlx &&
		(uint32_t)cl->plist->pos_y == cl->mlist->nly)
	{
		if (!(next_path = (char *)malloc((ft_strlen(
				cl->mlist->nlevel_path) + 1) * sizeof(char))))
			return (-1);
		ft_sprintf(next_path, "%s", cl->mlist->nlevel_path);
		ft_del_some(cl);
		ft_del_map(cl->mlist);
		if (!(cl->mlist = ft_init_map()))
			return (-1);
		ft_parse_map(next_path, cl);
		ft_wall_tex_init(cl);
		ft_memdel((void**)&next_path);
	}
	return (0);
}