-
Notifications
You must be signed in to change notification settings - Fork 1
/
is_possible.c
117 lines (108 loc) · 3.12 KB
/
is_possible.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
113
114
115
116
117
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_possible.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: majjig <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/07 03:19:14 by majjig #+# #+# */
/* Updated: 2021/12/12 00:54:30 by majjig ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
int is_move_up(t_mlx *mlx)
{
t_pos player;
player = find_player(mlx->map);
if (player.x == -1)
return (0);
if (mlx->map[player.y - 1][player.x] != WALL)
{
if (mlx->map[player.y - 1][player.x] == ENEMY)
{
mlx_loop_hook(mlx->mlx, &lose_page, mlx);
return (0);
}
if (mlx->map[player.y - 1][player.x] == EXIT && mlx->count == 0)
mlx_loop_hook(mlx->mlx, &win_page, mlx);
if (mlx->map[player.y - 1][player.x] != EXIT)
{
mlx->map[player.y - 1][player.x] = PLAYER;
mlx->map[player.y][player.x] = EMPTY;
return (1);
}
}
return (0);
}
int is_move_down(t_mlx *mlx)
{
t_pos player;
player = find_player(mlx->map);
if (player.x == -1)
return (0);
if (mlx->map[player.y + 1][player.x] != WALL)
{
if (mlx->map[player.y + 1][player.x] == ENEMY)
{
mlx_loop_hook(mlx->mlx, &lose_page, mlx);
return (0);
}
if (mlx->map[player.y + 1][player.x] == EXIT && mlx->count == 0)
mlx_loop_hook(mlx->mlx, &win_page, mlx);
if (mlx->map[player.y + 1][player.x] != EXIT)
{
mlx->map[player.y + 1][player.x] = PLAYER;
mlx->map[player.y][player.x] = EMPTY;
return (1);
}
}
return (0);
}
int is_move_right(t_mlx *mlx)
{
t_pos player;
player = find_player(mlx->map);
if (player.x == -1)
return (0);
if (mlx->map[player.y][player.x + 1] != WALL)
{
if (mlx->map[player.y][player.x + 1] == ENEMY)
{
mlx_loop_hook(mlx->mlx, &lose_page, mlx);
return (0);
}
if (mlx->map[player.y][player.x + 1] == EXIT && mlx->count == 0)
mlx_loop_hook(mlx->mlx, &win_page, mlx);
if (mlx->map[player.y][player.x + 1] != EXIT)
{
mlx->map[player.y][player.x + 1] = PLAYER;
mlx->map[player.y][player.x] = EMPTY;
return (1);
}
}
return (0);
}
int is_move_left(t_mlx *mlx)
{
t_pos player;
player = find_player(mlx->map);
if (player.x == -1)
return (0);
if (mlx->map[player.y][player.x - 1] != WALL)
{
if (mlx->map[player.y][player.x - 1] == ENEMY)
{
mlx_loop_hook(mlx->mlx, &lose_page, mlx);
return (0);
}
if (mlx->map[player.y][player.x - 1] == EXIT && mlx->count == 0)
mlx_loop_hook(mlx->mlx, &win_page, mlx);
if (mlx->map[player.y][player.x - 1] != EXIT)
{
mlx->map[player.y][player.x - 1] = PLAYER;
mlx->map[player.y][player.x] = EMPTY;
return (1);
}
}
return (0);
}