-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoves.c
110 lines (103 loc) · 3.12 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/29 10:33:05 by zwalad #+# #+# */
/* Updated: 2023/01/06 00:02:49 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub1d.h"
#include <stdio.h>
int mouse_turn(int keycode, int i, int j, t_big *p)
{
int s;
s = 1;
(void)j;
(void)keycode;
if (i > WIDTH / 2)
s = -1;
p->player.pa -= (PI / 40) * s;
if ((p->player.pa - (PI / 60)) < 0)
p->player.pa += 2 * PI;
else if ((p->player.pa + (PI / 60)) > 2 * PI)
p->player.pa = 0;
p->player.pdy = cos(p->player.pa);
p->player.pdx = sin(p->player.pa);
get_correct(p);
cast_rays(p);
mini_map(p);
return (0);
}
int mouse(int keycode, t_big *p)
{
(void)keycode;
(void)p;
exit(0);
return (0);
}
int ifmove(t_big *p, int ip, int jp)
{
int i;
int j;
i = (p->map.ip / SIZE);
j = (p->map.jp / SIZE);
if (ip <= 0 || jp <= 0 || ip >= p->map.i || jp >= ft_strlen(p->map.map[ip]))
return (0);
if (p->map.map[ip][jp] == '1' || p->map.map[i][jp] == '1'
|| p->map.map[ip][j] == '1')
return (0);
return (1);
}
void ft_mooove2(int keycode, t_big *p, int s)
{
if (keycode == 65361 || keycode == 65363)
{
if (keycode == 65363)
s = -1;
p->player.pa -= (PI / 40) * s;
if ((p->player.pa - (PI / 60)) < 0)
p->player.pa += 2 * PI;
else if ((p->player.pa + (PI / 60)) > 2 * PI)
p->player.pa = 0;
p->player.pdy = cos(p->player.pa);
p->player.pdx = sin(p->player.pa);
}
if (keycode == 119 && ifmove(p, ((p->map.ip + (p->player.pdx * STEPS)) \
/ SIZE), (p->map.jp + (p->player.pdy * STEPS)) / SIZE))
{
p->map.ip += p->player.pdx * STEPS;
p->map.jp += p->player.pdy * STEPS;
}
if (keycode == 115 && ifmove(p, ((p->map.ip - (p->player.pdx * STEPS)) \
/ SIZE), (p->map.jp - (p->player.pdy * STEPS)) / SIZE))
{
p->map.ip -= p->player.pdx * STEPS;
p->map.jp -= p->player.pdy * STEPS;
}
}
int ft_mooove(int keycode, t_big *p)
{
if (keycode == 97 && ifmove(p, ((p->map.ip - (cos(p->player.pa) * STEPS)) \
/ SIZE), (p->map.jp + (sin(p->player.pa) * STEPS)) / SIZE))
{
p->map.ip -= cos(p->player.pa) * STEPS;
p->map.jp += sin(p->player.pa) * STEPS;
}
if (keycode == 100 && ifmove(p, ((p->map.ip + (cos(p->player.pa) * STEPS)) \
/ SIZE), (p->map.jp - (sin(p->player.pa) * STEPS)) / SIZE))
{
p->map.ip += cos(p->player.pa) * STEPS;
p->map.jp -= sin(p->player.pa) * STEPS;
}
if (keycode == 53)
exito(p);
get_correct(p);
if (keycode)
ft_mooove2(keycode, p, 1);
cast_rays(p);
mini_map(p);
return (0);
}