-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.c
More file actions
73 lines (66 loc) · 2.25 KB
/
image.c
File metadata and controls
73 lines (66 loc) · 2.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* image.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sryou <sryou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/23 11:54:42 by sryou #+# #+# */
/* Updated: 2022/08/23 15:12:36 by sryou ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void place_image(t_game *game, int width, int height)
{
int (*f)();
f = mlx_put_image_to_window;
f(game->mlx, game->win, game->img.grass, width * 64, height * 64);
if (game->map[height * game->width + width] == '1')
f(game->mlx, game->win, game->img.wall, width * 64, height * 64);
if (game->map[height * game->width + width] == 'C')
f(game->mlx, game->win, game->img.item, width * 64, height * 64);
if (game->map[height * game->width + width] == 'E')
f(game->mlx, game->win, game->img.exit, width * 64, height * 64);
if (game->map[height * game->width + width] == 'P')
f(game->mlx, game->win, game->img.user, width * 64, height * 64);
}
void print_map(t_game *game)
{
int width;
int height;
height = 0;
while (height < game->height)
{
width = 0;
while (width < game->width)
{
place_image(game, width, height);
width++;
}
height++;
}
}
void move(t_game *game, int cordMove)
{
int flag_quit;
flag_quit = 0;
if (game->map[cordMove] == '1')
return ;
if (game->map[cordMove] == 'C')
game->collected_item++;
if (game->map[cordMove] == 'E')
{
if (game->collected_item == game->num_item)
flag_quit = 1;
else
return ;
}
game->map[cordMove] = 'P';
game->map[game->cord_user] = '0';
game->cord_user = cordMove;
ft_putnbr_fd(++game->current_move, 1);
ft_putchar_fd('\n', 1);
print_map(game);
if (flag_quit)
quit(game, 0);
}