-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
81 lines (74 loc) · 2.59 KB
/
main.c
File metadata and controls
81 lines (74 loc) · 2.59 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sfelici <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 15:06:57 by sfelici #+# #+# */
/* Updated: 2025/02/21 15:13:53 by sfelici ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int close_game(t_vars *vars)
{
ft_cleanup(vars);
exit(0);
return (0);
}
int init_textures(t_vars *vars)
{
int w;
int h;
vars->textures.wall_img = mlx_xpm_file_to_image(vars->mlx,
"textures/cobblestone.xpm", &w, &h);
vars->textures.floor_img = mlx_xpm_file_to_image(vars->mlx,
"textures/grass.xpm", &w, &h);
vars->textures.collectible_img = mlx_xpm_file_to_image(vars->mlx,
"textures/ender_eye.xpm", &w, &h);
vars->textures.exit_img_closed = mlx_xpm_file_to_image(vars->mlx,
"textures/end_portal_closed.xpm", &w, &h);
vars->textures.exit_img_open = mlx_xpm_file_to_image(vars->mlx,
"textures/end_portal_open.xpm", &w, &h);
vars->textures.player_img = mlx_xpm_file_to_image(vars->mlx,
"textures/player.xpm", &w, &h);
vars->textures.enemy_img = mlx_xpm_file_to_image(vars->mlx,
"textures/enemy.xpm", &w, &h);
vars->textures.explosion_img = mlx_xpm_file_to_image(vars->mlx,
"textures/explosion.xpm", &w, &h);
vars->textures.flint_img = mlx_xpm_file_to_image(vars->mlx,
"textures/flint.xpm", &w, &h);
return (0);
}
static void init_game(t_vars *vars)
{
vars->mlx = mlx_init();
vars->win = mlx_new_window(vars->mlx,
vars->map_info.cols * GRID_SIZE,
vars->map_info.rows * GRID_SIZE, "So Long");
sleep(1);
init_textures(vars);
init_enemies(vars);
draw_map(vars);
mlx_hook(vars->win, 2, 1L << 0, key_press, vars);
mlx_hook(vars->win, 17, 0, close_game, vars);
mlx_loop(vars->mlx);
}
int main(int argc, char **argv)
{
t_vars vars;
ft_bzero(&vars, sizeof(t_vars));
if (argc == 2)
{
vars.map = read_map(argv[1]);
if (!vars.map)
return (1);
if (check_map_errors(vars.map, &vars.map_info))
{
free_map(vars.map);
return (1);
}
init_game(&vars);
}
return (0);
}