-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
77 lines (70 loc) · 2.46 KB
/
main.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 17:02:14 by zwalad #+# #+# */
/* Updated: 2023/01/05 18:25:31 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub1d.h"
void ft_error(char *str)
{
write(2, "error: ", 8);
write(2, str, ft_strlen(str));
write(2, "\n", 1);
exit(1);
}
void sub_main(t_big *p)
{
check_path(p->file, ".cub");
get_contents(p);
check_map(p);
check_texture(p);
get_player(p);
ckeck_zero(p);
get_xy(p);
p->player.pdx = sin(p->player.pa);
p->player.pdy = cos(p->player.pa);
p->map.ip = (SIZE * p->map.ip) + (SIZE / 2);
p->map.jp = (SIZE * p->map.jp) + (SIZE / 2);
get_colors(p);
}
void get_colors(t_big *p)
{
p->content.ff = get_rgb(p->content.fn[0], \
p->content.fn[1], p->content.fn[2]);
p->content.cc = get_rgb(p->content.cn[0], \
p->content.cn[1], p->content.cn[2]);
}
int get_rgb(int red, int green, int blue)
{
return (red << 16 | green << 8 | blue);
}
int main(int ac, char **av)
{
t_big *p;
if (ac != 2)
ft_error("arguments !");
p = malloc(sizeof(t_big));
p->file = ft_strdup(av[1]);
sub_main(p);
p->mlx.mlx_ptr = mlx_init();
p->image.ptr = mlx_new_image(p->mlx.mlx_ptr, WIDTH, HEIGHT);
p->image.addr = mlx_get_data_addr(p->image.ptr,
&p->image.bts_pxt, &p->image.len, &p->image.endn);
p->mlx.win_ptr = mlx_new_window(p->mlx.mlx_ptr, WIDTH, HEIGHT, "cub3D");
//p->weapon.ptr = mlx_xpm_file_to_image(p->mlx.mlx_ptr, "./img/weapon.xpm", &p->weapon.width, &p->weapon.height);
int weapon_x = (WIDTH - p->weapon.width) / 2;
int weapon_y = HEIGHT - p->weapon.height;
image_init(p);
cast_rays(p);
read_map(p, -1, -4);
mlx_hook(p->mlx.win_ptr, 2, 1L, ft_mooove, p);
mlx_hook(p->mlx.win_ptr, 17, 0, mouse, p);
mlx_hook(p->mlx.win_ptr, 4, 1L << 2, mouse_turn, p);
mlx_loop(p->mlx.mlx_ptr);
return (0);
}