-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoveplayer1.c
45 lines (41 loc) · 1.67 KB
/
moveplayer1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* movplayer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/24 06:27:15 by abadidi #+# #+# */
/* Updated: 2021/11/25 01:54:13 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int ft_printmv(t_data *data)
{
data->mv++;
ft_putnbr(data->mv);
write(1, "\n", 1);
return (1);
}
// void helper2(t_data *data, int key)
// {
// if (((data->p_x - TS) >= 0 && (data->p_x + TS) <= data->w * TS)
// && iswall(data, data->p_x + TS, data->p_y) == 0)
// {
// if (key == D_KEY && ft_printmv(data))
// data->p_x += TS;
// }
// }
void helper(t_data *d, int key)
{
if (key == ESC)
ft_destroywindown(d);
if (key == W_KEY && iswall(d, d->p_x, d->p_y - TS) == 0 && ft_printmv(d))
d->p_y -= TS;
if (key == S_KEY && iswall(d, d->p_x, d->p_y + TS) == 0 && ft_printmv(d))
d->p_y += TS;
if (key == A_KEY && iswall(d, d->p_x - TS, d->p_y) == 0 && ft_printmv(d))
d->p_x -= TS;
if (key == D_KEY && iswall(d, d->p_x + TS, d->p_y) == 0 && ft_printmv(d))
d->p_x -= TS;
}