-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
58 lines (52 loc) · 1.75 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/11 13:42:17 by sanan #+# #+# */
/* Updated: 2023/10/24 13:39:22 by sanan ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
int main(int ac, char **av)
{
t_info info;
t_game game;
if (ac != 2 || is_extension_valid(av[1]))
exit_error(ERR_ARG);
info_init(&info, av[1]);
init_map(&info, &game);
init_game_mlx(&game);
mlx_put_image_to_window(game.mlx, game.win, game.img, 0, 0);
hook_key_events(&game);
mlx_loop_hook(game.mlx, &run_game, &game);
mlx_loop(game.mlx);
}
int run_game(t_game *game)
{
raycast(game);
mlx_put_image_to_window(game->mlx, game->win, game->img, 0, 0);
read_keys_and_move(game);
return (1);
}
void raycast(t_game *game)
{
int x;
x = 0;
while (x < SCREEN_WIDTH)
{
game->camera_x = 2 * x / (double)SCREEN_WIDTH - 1;
set_ray_direction(game);
set_map_position(game);
set_delta_distance(game);
set_side_distance(game);
dda(game);
set_draw_range(game);
calculate_texture(game);
set_draw_buffer(game, x);
x++;
}
put_buffer_to_image(game);
}