-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathso_long_graphics.c
More file actions
101 lines (95 loc) · 3.08 KB
/
so_long_graphics.c
File metadata and controls
101 lines (95 loc) · 3.08 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_long_graphics.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: belamiqu <belamiqu@student.42urduliz.co +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/24 12:35:10 by belamiqu #+# #+# */
/* Updated: 2023/12/07 20:07:12 by belamiqu ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_keyhook(int keycode, t_map *m)
{
ft_init_m(m);
if (keycode == 53)
exit(0);
if (keycode == 2 || keycode == 124)
if (m->str[m->player_x][m->player_y + 1] != 1)
ft_move_right(m);
if (keycode == 1 || keycode == 125)
if (m->str[m->player_x + 1][m->player_y] != 1)
ft_move_down(m);
if (keycode == 0 || keycode == 123)
if (m->str[m->player_x][m->player_y - 1] != 1)
ft_move_left(m);
if (keycode == 13 || keycode == 126)
if (m->str[m->player_x - 1][m->player_y] != 1)
ft_move_up(m);
mlx_clear_window(m->mlx, m->window);
ft_render_window(m);
return (0);
}
int ft_exit_rb(t_map *m)
{
mlx_destroy_window(m->mlx, m->window);
free(m->str);
free(m->map);
exit (0);
}
void ft_put_image_window(t_map *m)
{
if (m->str[m->i][m->j] == '1')
mlx_put_image_to_window(m->mlx, m->window, m->tree,
m->y, m->c);
else if (m->str[m->i][m->j] == '0')
mlx_put_image_to_window(m->mlx, m->window, m->snow,
m->y, m->c);
else if (m->str[m->i][m->j] == 'C')
mlx_put_image_to_window(m->mlx, m->window, m->bird,
m->y, m->c);
else if (m->str[m->i][m->j] == 'P')
mlx_put_image_to_window(m->mlx, m->window, m->snoopy,
m->y, m->c);
else if (m->str[m->i][m->j] == 'E')
mlx_put_image_to_window(m->mlx, m->window, m->house,
m->y, m->c);
}
void ft_render_window(t_map *m)
{
ft_init_m(m);
m->c = -50;
while (m->str[m->i])
{
m->j = 0;
m->c = m->c + 50;
m->y = 0;
while (m->str[m->i][m->j])
{
ft_put_image_window(m);
m->y = m->y + 50;
m->j++;
}
m->i++;
}
}
void ft_start_window(t_map *m)
{
m->mlx = mlx_init();
m->img_width = 50;
m->img_height = 50;
m->window = mlx_new_window(m->mlx, m->img_width * m->width,
m->img_height * m->num_lines, "SO_LONG");
m->house = mlx_xpm_file_to_image(m->mlx, "./textures/exit.xpm",
&m->img_width, &m->img_height);
m->snow = mlx_xpm_file_to_image(m->mlx, "./textures/floor.xpm",
&m->img_width, &m->img_height);
m->bird = mlx_xpm_file_to_image(m->mlx, "./textures/coin.xpm",
&m->img_width, &m->img_height);
m->snoopy = mlx_xpm_file_to_image(m->mlx, "./textures/player.xpm",
&m->img_width, &m->img_height);
m->tree = mlx_xpm_file_to_image(m->mlx, "./textures/wall.xpm",
&m->img_width, &m->img_height);
ft_render_window(m);
}