blob: b9dbfd3b0c29c5d8fde53c876cf51b3cacc85cae (
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_init_lists.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:28:53 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:28:53 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
#include <mlx.h>
#include <cub3d.h>
#include <stddef.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
static t_rgb
ft_init_rgb(void)
{
t_rgb rgb;
rgb.r = -1;
rgb.g = -1;
rgb.b = -1;
return (rgb);
}
static t_player
*ft_init_player(void)
{
t_player *plist;
if (!(plist = (t_player*)malloc(sizeof(t_player))))
return (NULL);
plist->pos_x = 0;
plist->pos_y = 0;
plist->start_x = 0;
plist->start_y = 0;
plist->cam_x = 0;
plist->dir_x = -1;
plist->dir_y = 0;
plist->plane_x = 0;
plist->plane_y = 0.66666666;
plist->life = 100;
return (plist);
}
static t_win
*ft_init_win(void)
{
t_win *wlist;
if (!(wlist = (t_win*)malloc(sizeof(t_win))))
return (NULL);
if (!(wlist->wlx = malloc(1)) ||
!(wlist->winptr = malloc(1)))
return (NULL);
wlist->inited = 0;
wlist->x_size = 0;
wlist->y_size = 0;
wlist->x_max_size = 0;
wlist->y_max_size = 0;
return (wlist);
}
static t_cub
*ft_init_cub(void)
{
t_cub *clist;
uint8_t i;
if (!(clist = (t_cub*)malloc(sizeof(t_cub))))
return (NULL);
if (!(clist->plist = ft_init_player()) ||
!(clist->mlist = ft_init_map()))
return (NULL);
ft_bzero(clist->errmsg, 40);
i = -1;
while (++i < 5)
clist->key_input[i] = -1;
clist->ishud = 0;
clist->f_rgb = ft_init_rgb();
clist->c_rgb = ft_init_rgb();
clist->rlist = ft_init_s_ray();
clist->key_ptr[0] = ft_w_key;
clist->key_ptr[1] = ft_a_key;
clist->key_ptr[2] = ft_s_key;
clist->key_ptr[3] = ft_d_key;
clist->key_ptr[4] = ft_left_key;
clist->key_ptr[5] = ft_right_key;
return (clist);
}
int8_t
ft_init_cub3d(t_cub **clist)
{
t_cub *cl;
if (!(cl = ft_init_cub()))
{
ft_memdel((void**)&cl);
return (-1);
}
if (!(cl->wlist = ft_init_win()))
{
ft_memdel((void**)&cl->wlist);
ft_memdel((void**)&cl);
return (-1);
}
*clist = cl;
return (0);
}
|