-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_img.c
65 lines (59 loc) · 1.81 KB
/
move_img.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* move_img.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dyoula <dyoula@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/20 23:31:19 by dyoula #+# #+# */
/* Updated: 2022/01/25 18:12:56 by dyoula ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int find_pixels(t_vars *g)
{
int pix_x;
int pix_y;
pix_x = g->data.player_x * 40;
pix_y = g->data.player_y * 40;
mlx_put_image_to_window(g->data.mlx_ptr, g->data.win_ptr, \
g->image[1].img, pix_x, pix_y);
return (1);
}
int find_previous(t_vars *g, int x, int y)
{
int pix_x;
int pix_y;
pix_x = x * 40;
pix_y = y * 40;
mlx_put_image_to_window(g->data.mlx_ptr, g->data.win_ptr, \
g->image[3].img, pix_x, pix_y);
return (1);
}
void player_moved(int n, t_vars *g)
{
if (n == UP)
{
find_pixels(g);
find_previous(g, g->data.player_x, g->data.player_y + 1);
return ;
}
else if (n == DOWN)
{
find_pixels(g);
find_previous(g, g->data.player_x, g->data.player_y - 1);
return ;
}
else if (n == LEFT)
{
find_pixels(g);
find_previous(g, g->data.player_x + 1, g->data.player_y);
return ;
}
else if (n == RIGHT)
{
find_pixels(g);
find_previous(g, g->data.player_x - 1, g->data.player_y);
return ;
}
}