-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_player_next_pos.c
77 lines (67 loc) · 1.91 KB
/
get_player_next_pos.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
75
76
77
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_player_next_pos.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: majjig <majjig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/07 03:19:50 by majjig #+# #+# */
/* Updated: 2021/12/12 00:56:52 by majjig ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
void move_up(t_mlx *mlx, t_pos *pos)
{
int i;
i = ELEMENT_LEN / SPEED;
while (i--)
{
between_move(mlx);
pos->y -= SPEED;
}
printf("Moves: %d\n", mlx->moves++);
}
void move_down(t_mlx *mlx, t_pos *pos)
{
int i;
i = ELEMENT_LEN / SPEED;
while (i--)
{
between_move(mlx);
pos->y += SPEED;
}
printf("Moves: %d\n", mlx->moves++);
}
void move_right(t_mlx *mlx, t_pos *pos)
{
int i;
i = ELEMENT_LEN / SPEED;
while (i--)
{
between_move(mlx);
pos->x += SPEED;
}
printf("Moves: %d\n", mlx->moves++);
}
void move_left(t_mlx *mlx, t_pos *pos)
{
int i;
i = ELEMENT_LEN / SPEED;
while (i--)
{
between_move(mlx);
pos->x -= SPEED;
}
printf("Moves: %d\n", mlx->moves++);
}
void get_player_next_pos(int key, t_mlx *mlx, t_pos *pos)
{
if (key == MOVE_UP && is_move_up(mlx))
move_up(mlx, pos);
else if (key == MOVE_DOWN && is_move_down(mlx))
move_down(mlx, pos);
else if (key == MOVE_RIGHT && is_move_right(mlx))
move_right(mlx, pos);
else if (key == MOVE_LEFT && is_move_left(mlx))
move_left(mlx, pos);
}