-
Notifications
You must be signed in to change notification settings - Fork 0
/
wolf3D.c
126 lines (119 loc) · 3.48 KB
/
wolf3D.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
118
119
120
121
122
123
124
125
126
/*
** wolf3D.c for in /home/bertra_v/tek_1/IGraph/MUL_2014_wolf3d
**
** Made by Florent Bertrand
** Login <[email protected]>
**
** Started on Tue Dec 16 20:51:02 2014 Florent Bertrand
** Last update Sun Dec 21 17:08:00 2014 Florent Bertrand
*/
#include <stdlib.h>
#include <math.h>
#include <X11/XKBlib.h>
#include "my.h"
#include "mlx.h"
#include "wolf3D.h"
#include "map.h"
int key_hook(int keycode, t_mlx *mlx)
{
if (keycode == 65307)
exit(0);
if (keycode == 65362 &&
map[mlx->niv][(int)(mlx->params->Xo + cos(mlx->params->angle))]
[(int)(mlx->params->Yo + sin(mlx->params->angle))] == 0)
{
mlx->params->Xo += cos(mlx->params->angle) * 0.3;
mlx->params->Yo += sin(mlx->params->angle) * 0.3;
wolf_calc(mlx, mlx->params);
}
if (keycode == 65364 &&
map[mlx->niv][(int)(mlx->params->Xo - cos(mlx->params->angle) * 0.25)]
[(int)(mlx->params->Yo - sin(mlx->params->angle) * 0.25)] == 0)
{
mlx->params->Xo -= cos(mlx->params->angle) * 0.1;
mlx->params->Yo -= sin(mlx->params->angle) * 0.1;
wolf_calc(mlx, mlx->params);
}
key_hook2(keycode, mlx);
return (0);
}
int key_hook2(int keycode, t_mlx *mlx)
{
if (keycode == 65363)
{
mlx->params->angle -= 0.1;
wolf_calc(mlx, mlx->params);
}
if (keycode == 65361)
{
mlx->params->angle += 0.1;
wolf_calc(mlx, mlx->params);
}
if (keycode == 65470)
XkbSetAutoRepeatRate(((t_xvar*)mlx->mlx)->display, XkbUseCoreKbd,
REFRESH_OPTION, REFRESH_OPTION);
if (keycode == 65471)
XkbSetAutoRepeatRate(((t_xvar*)mlx->mlx)->display, XkbUseCoreKbd,
660, 40);
key_hook3(keycode, mlx);
return (0);
}
int key_hook3(int keycode, t_mlx *mlx)
{
if (keycode == 65362 &&
map[mlx->niv][(int)(mlx->params->Xo + cos(mlx->params->angle))]
[(int)(mlx->params->Yo + sin(mlx->params->angle))] == 2)
{
mlx->niv++;
wolf_calc(mlx, mlx->params);
}
if (keycode == 65362 &&
map[mlx->niv][(int)(mlx->params->Xo + cos(mlx->params->angle))]
[(int)(mlx->params->Yo + sin(mlx->params->angle))] == 3)
{
mlx->niv++;
wolf_calc(mlx, mlx->params);
}
if (keycode == 65362 &&
map[mlx->niv][(int)(mlx->params->Xo + cos(mlx->params->angle))]
[(int)(mlx->params->Yo + sin(mlx->params->angle))] == 4)
{
my_putstr("Bravo, tu as trouvé la sortie du labyrinthe ");
my_putstr("brave aventurier tu as le droit à un: Kinder");
exit(3);
}
return (0);
}
void expose_hook(t_mlx *mlx)
{
mlx_put_image_to_window(mlx->mlx, mlx->window, mlx->img, 0, 0);
mlx_put_image_to_window(mlx->mlx, mlx->window, mlx->gun,
(WIDTH - (2 * mlx->gun->width)),
(HEIGHT - (mlx->gun->height)));
}
int main(int ac, char **av)
{
t_params params;
t_mlx mlx;
mlx.niv = 0;
if ((mlx.mlx = mlx_init()) == NULL)
{
my_putstr("Don't touch my environnement !!!");
return (0);
}
mlx.window = mlx_new_window(mlx.mlx, WIDTH, HEIGHT, "Wolflictum3D");
mlx.img = mlx_new_image(mlx.mlx, WIDTH, HEIGHT);
mlx.gun = mlx_xpm_file_to_image(mlx.mlx, "gun.xpm", &mlx.gx, &mlx.gy);
params.Xo = 1.5;
params.Yo = 1.5;
params.angle = M_PI / 4;
mlx.params = ¶ms;
wolf_calc(&mlx, ¶ms);
mlx_put_image_to_window(mlx.mlx, mlx.window, mlx.gun,
(WIDTH - (2 * mlx.gun->width)),
(HEIGHT - (mlx.gun->height)));
mlx_expose_hook(mlx.window, expose_hook, &mlx);
mlx_hook(mlx.window, KeyPress, KeyPressMask, key_hook, &mlx);
mlx_loop(mlx.mlx);
return (0);
}