-
Notifications
You must be signed in to change notification settings - Fork 0
/
so_moves.c
112 lines (105 loc) · 3.29 KB
/
so_moves.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* so_moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/06 10:37:42 by zwalad #+# #+# */
/* Updated: 2022/02/10 17:18:08 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_test.h"
int ft_move_y(int keycode, t_jinx *p, int x, int y)
{
if (keycode == 125 || keycode == 1)
{
p->p_path = player_banania(keycode);
putfloor(p, x, y);
y += 80;
p->player = mlx_xpm_file_to_image(p->mlx_ptr, p->p_path, &p->w, &p->h);
putfloor(p, x, y);
mlx_put_image_to_window(p->mlx_ptr, p->win_ptr, p->player, x, y);
}
if (keycode == 126 || keycode == 13)
{
p->p_path = player_banania(keycode);
putfloor(p, x, y);
y -= 80;
p->player = mlx_xpm_file_to_image(p->mlx_ptr, p->p_path, &p->w, &p->h);
putfloor(p, x, y);
mlx_put_image_to_window(p->mlx_ptr, p->win_ptr, p->player, x, y);
}
return (y);
}
int ft_move_x(int keycode, t_jinx *p, int x, int y)
{
if (keycode == 124 || keycode == 2)
{
p->p_path = player_banania(keycode);
putfloor(p, x, y);
x += 80;
p->player = mlx_xpm_file_to_image(p->mlx_ptr, p->p_path, &p->w, &p->h);
putfloor(p, x, y);
mlx_put_image_to_window(p->mlx_ptr, p->win_ptr, p->player, x, y);
}
if (keycode == 123 || keycode == 0)
{
p->p_path = player_banania(keycode);
putfloor(p, x, y);
x -= 80;
p->player = mlx_xpm_file_to_image(p->mlx_ptr, p->p_path, &p->w, &p->h);
putfloor(p, x, y);
mlx_put_image_to_window(p->mlx_ptr, p->win_ptr, p->player, x, y);
}
return (x);
}
int ft_mouve(int keycode, t_jinx *p)
{
static int x;
static int y;
static int i;
t_vi q;
if (i == 0)
{
q = spawn_p(p, &q);
x = q.xx;
y = q.yy;
i++;
}
check_collec(p, x, y);
if (!(wall_check(p, keycode, x, y))
|| (mapchr(p, 'C') > 0 && exit_block(p, keycode, x, y)))
return (0);
check_close(keycode, p, x, y);
if (keycode == 124 || keycode == 2 || keycode == 123 || keycode == 0)
x = sub_move_x(keycode, x, y, p);
if (keycode == 125 || keycode == 1 || keycode == 126 || keycode == 13)
y = sub_move_y(keycode, x, y, p);
if (keycode == 124 || keycode == 2 || keycode == 123 || keycode == 0
|| keycode == 125 || keycode == 1 || keycode == 126 || keycode == 13)
ft_printf("your move is : %d\n", i++);
return (0);
}
int sub_move_x(int keycode, int x, int y, t_jinx *p)
{
if (wall_check(p, keycode, x, y))
{
if (keycode == 124 || keycode == 2 || keycode == 123 || keycode == 0)
{
x = ft_move_x(keycode, p, x, y);
}
}
return (x);
}
int sub_move_y(int keycode, int x, int y, t_jinx *p)
{
if (wall_check(p, keycode, x, y))
{
if (keycode == 125 || keycode == 1 || keycode == 126 || keycode == 13)
{
y = ft_move_y(keycode, p, x, y);
}
}
return (y);
}