-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics.c
74 lines (66 loc) · 2.5 KB
/
graphics.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
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* graphics.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abertran <abertran@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/17 22:59:55 by abertran #+# #+# */
/* Updated: 2023/04/17 22:59:55 by abertran ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void place_player(t_start *game, int height, int width)
{
mlx_put_image_to_window(game->mlx,
game->window, game->player, width * 45, height * 45);
game->y_axis = height;
game->x_axis = width;
}
void place_collectable(t_start *game, int height, int width)
{
mlx_put_image_to_window(game->mlx,
game->window, game->collectable, width * 45, height * 45);
game->collectables++;
}
void put_images(t_start *game)
{
game->floor = valid_xpm(game, "textures/grass.xpm");
game->barrier = valid_xpm(game, "textures/tree.xpm");
game->player = valid_xpm(game, "textures/oldman.xpm");
game->exit = valid_xpm(game, "textures/exit.xpm");
game->collectable = valid_xpm(game, "textures/tooth.xpm");
}
void put_graphics1(t_start *game, int height)
{
int width;
while (height < game->mapheight)
{
width = 0;
while (game->map[height][width])
{
if (game->map[height][width] == '1')
mlx_put_image_to_window(game->mlx, game->window,
game->barrier, width * 45, height * 45);
if (game->map[height][width] == 'C')
place_collectable(game, height, width);
if (game->map[height][width] == 'P')
place_player(game, height, width);
if (game->map[height][width] == 'E')
mlx_put_image_to_window(game->mlx,
game->window, game->exit, width * 45, height * 45);
if (game->map[height][width] == '0')
mlx_put_image_to_window(game->mlx,
game->window, game->floor, width * 45, height * 45);
width++;
}
height++;
}
}
void put_graphics(t_start *game)
{
int height;
game->collectables = 0;
height = 0;
put_graphics1(game, height);
}