-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathso_long_game.c
More file actions
64 lines (58 loc) · 1.83 KB
/
Copy pathso_long_game.c
File metadata and controls
64 lines (58 loc) · 1.83 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long_game.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cerdelen <cerdelen@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/07 17:26:36 by cerdelen #+# #+# */
/* Updated: 2022/03/07 17:26:37 by cerdelen ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void free_and_exit(t_vars *vars)
{
int i;
i = 0;
while (i < vars->map_data.rows)
{
free(vars->map_data.map[i]);
i++;
}
free(vars->map_data.map);
exit(EXIT_SUCCESS);
}
int close_game(t_vars *vars)
{
mlx_destroy_window(vars->mlx, vars->win);
free_and_exit(vars);
return (0);
}
int key_press(int key, t_vars *vars)
{
if (key == 13)
move_up(vars);
if (key == 0)
move_left(vars);
if (key == 1)
move_down(vars);
if (key == 2)
move_right(vars);
if (key == 53)
close_game(vars);
render_map(vars);
return (0);
}
void game_function(t_vars vars)
{
vars.map_data.moves = 0;
vars.mlx = mlx_init();
get_images(&vars.game_images, vars.mlx, &vars);
vars.win = mlx_new_window(vars.mlx, (vars.game_images.widht
* vars.map_data.columns), (vars.game_images.height
* vars.map_data.rows), "so_long");
render_map(&vars);
mlx_key_hook(vars.win, key_press, &vars);
mlx_hook(vars.win, 17, 0, close_game, &vars);
mlx_loop(vars.mlx);
}