aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_init_lists.c
blob: 4a8d91dfce6e912ec87ecf19b62b36509404988f (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_init_lists.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: joelecle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:28:53 by joelecle          #+#    #+#             */
/*   Updated: 2020/02/14 17:28:53 by joelecle         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

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

t_rgb
	ft_init_rgb(void)
{
	t_rgb	rgb;

	rgb.r = -1;
	rgb.g = -1;
	rgb.b = -1;
	return (rgb);
}

/*
** handles_weapon
** --------------
** -1: no weapon
**  0: weapon one
**  2: weapon two
**  4: weapon three
*/

t_player
	ft_init_player(void)
{
	t_player	plist;

	plist.pos_x = 0;
	plist.pos_y = 0;
	plist.pos_z = 0;
	plist.start_x = 0;
	plist.start_y = 0;
	plist.cam_x = 0;
	plist.dir_y = 1;
	plist.dir_x = 0;
	plist.plane_x = 0;
	plist.plane_y = 0.66;
	plist.has_weapon[0] = 0;
	plist.has_weapon[1] = 0;
	plist.has_weapon[2] = 0;
	plist.handles_weapon = -1;
	plist.ammo[0] = 0;
	plist.ammo[1] = 0;
	plist.ammo[2] = 0;
	plist.life = FT_STRT_LIFE;
	plist.fire = 0;
	plist.weap_vel[0] = FT_WEAP_ONE_VEL;
	plist.weap_vel[1] = FT_WEAP_TWO_VEL;
	plist.weap_vel[2] = FT_WEAP_THREE_VEL;
	return (plist);
}

static int8_t
	ft_init_win(t_win *wl)
{
	if (!(wl->wlx = malloc(1)))
		return (-1);
	if (!(wl->winptr = malloc(1)))
		return (-1);
	wl->inited = 0;
	wl->x_size = 0;
	wl->y_size = 0;
	wl->x_max_size = 0;
	wl->y_max_size = 0;
	return (0);
}

static int8_t
	ft_init_cub(t_cub *cl)
{
	int8_t		i;

	if (ft_init_map(&cl->mlist) < 0)
		return (-1);
	cl->plist = ft_init_player();
	ft_bzero(cl->errmsg, 40);
	i = -1;
	while (++i < 5)
		cl->key_input[i] = -1;
	cl->mtid = 0;
	cl->ishud = 0;
	cl->isoldmus = 0;
	cl->doicast = 1;
	cl->f_rgb = ft_init_rgb();
	cl->c_rgb = ft_init_rgb();
	cl->rlist = ft_init_s_ray();
	cl->currlvl = 0;
	cl->walltexgood = 0;
	cl->clickclose = 0;
	ft_init_funptr(cl);
	ft_init_ref(cl);
	return (0);
}

int8_t
	ft_init_cub3d(t_cub *clist)
{
	if (ft_init_cub(clist) < 0)
		return (-1);
	if (ft_init_win(&clist->wlist) < 0)
		return (-1);
	if (ft_init_sprites(&clist->sprites) < 0)
		return (-1);
	if (!(clist->big_t = (float**)ft_calloc(2, sizeof(float*))) ||
		!(clist->big_t[0] = (float*)ft_calloc(1, sizeof(float))) ||
		!(clist->big_t[1] = (float*)ft_calloc(1, sizeof(float))))
		return (-1);
	clist->big_t_val = 2;
	ft_sprintf(clist->fps_count, "fps: 60");
	clist->isdead = 0;
	clist->moves = 0;
	clist->life_num_h = 0;
	clist->life_num_w = 0;
	clist->life_cap_h = 0;
	clist->life_cap_w = 0;
	clist->map_back_h = 0;
	clist->map_back_w = 0;
	clist->amm_back_h = 0;
	clist->amm_back_w = 0;
	clist->ammo_cap_h = 0;
	clist->ammo_cap_w = 0;
	return (0);
}