-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_image.c
70 lines (65 loc) · 2.72 KB
/
init_image.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: deleusis <deleusis@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 18:02:16 by deleusis #+# #+# */
/* Updated: 2022/02/26 19:30:16 by deleusis ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int init_image(t_prog *prog)
{
prog->wall.image = mlx_xpm_file_to_image(prog->mlx_ptr, WALL,
&prog->wall.width, &prog->wall.height);
prog->ground.image = mlx_xpm_file_to_image (prog->mlx_ptr, GROUND,
&prog->ground.width, &prog->ground.height);
prog->player.image = mlx_xpm_file_to_image (prog->mlx_ptr, PLAYER,
&prog->player.width, &prog->player.height);
prog->collectable.image = mlx_xpm_file_to_image (prog->mlx_ptr, COLLECTABLE,
&prog->collectable.width, &prog->collectable.height);
prog->exit.image = mlx_xpm_file_to_image (prog->mlx_ptr, EXIT,
&prog->exit.width, &prog->exit.height);
prog->enemy.image = mlx_xpm_file_to_image (prog->mlx_ptr, ENEMY,
&prog->enemy.width, &prog->enemy.height);
return (0);
}
int put_image(t_prog *prog)
{
int x;
int y;
y = -1;
mlx_clear_window(prog->mlx_ptr, prog->win_ptr);
while (prog->map[++y])
{
x = -1;
while (prog->map[y][++x])
put_image1(prog, x, y);
}
return (0);
}
void put_image1(t_prog *prog, int x, int y)
{
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->ground.image, x * 64, y * 64);
if (prog->map[y][x] == '1')
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->wall.image, x * 64, y * 64);
else if (prog->map[y][x] == '0')
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->ground.image, x * 64, y * 64);
else if (prog->map[y][x] == 'P')
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->player.image, x * 64, y * 64);
else if (prog->map[y][x] == 'E')
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->exit.image, x * 64, y * 64);
else if (prog->map[y][x] == 'C')
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->collectable.image, x * 64, y * 64);
else if (prog->map[y][x] == 'H')
mlx_put_image_to_window(prog->mlx_ptr, prog->win_ptr,
prog->enemy.image, x * 64, y * 64);
}