-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.c
100 lines (91 loc) · 2.22 KB
/
cub3d.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbalman <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/10 09:52:40 by prranges #+# #+# */
/* Updated: 2022/02/03 16:56:32 by mbalman ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int close_win(t_data *g)
{
if (g->mlx)
{
mlx_clear_window(g->mlx, g->win);
mlx_destroy_window(g->mlx, g->win);
}
exit (0);
}
void draw(t_data *g)
{
int x;
int y;
y = 0;
while (y < WIN_H)
{
x = 0;
while (x < WIN_W)
{
g->img.data[y * WIN_W + x] = g->screen_buf[y][x];
x++;
}
y++;
}
if (BONUS)
minimap(g);
mlx_put_image_to_window(g->mlx, g->win, g->img.img, 0, 0);
}
int game_loop(t_data *g)
{
floor_and_ceiling(g);
if (BONUS)
door(g);
wall_casting(g);
draw(g);
key_update(g);
return (0);
}
int txtrs_malloc(t_data *g)
{
int j;
int i;
j = 0;
g->txtrs = (int **)malloc(sizeof(int *) * 5);
if (!g->txtrs)
return (-1);
i = 0;
while (i < 5)
{
g->txtrs[i] = (int *)malloc(sizeof(int) * (TXTR_H * TXTR_W));
if (!g->txtrs[i])
return (-1);
i++;
}
return (0);
}
int main(int argc, char **argv)
{
t_data *g;
g = malloc(sizeof(t_data));
data_init(g);
ft_init(g);
ft_map_volidation(argc, argv, g);
ft_pars_params(argv, g);
if (txtrs_malloc(g))
exit(1);
load_texture(g);
mlx_loop_hook(g->mlx, &game_loop, g);
mlx_hook(g->win, PRESS, 0, &key_press, g);
mlx_hook(g->win, RELEASE, 0, &key_release, g);
mlx_hook(g->win, 17, 0L, close_win, g);
if (BONUS)
{
mlx_mouse_move(g->win, WIN_W / 2, WIN_H / 2);
mlx_mouse_hide();
mlx_hook(g->win, MOUSE, 0, mouse_move, g);
}
mlx_loop(g->mlx);
}