-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.c
77 lines (68 loc) · 1.57 KB
/
key.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
/*
** key.c for key hook function in /home/kerebe_p/git/MUL_2014_wolf3d
**
** Made by Paul Kerebel
** Login <[email protected]>
**
** Started on Mon Dec 15 21:04:02 2014 Paul Kerebel
** Last update Mon Dec 15 21:09:49 2014 Paul Kerebel
*/
#include "include/my.h"
void up_move(s_move *game)
{
float x;
float y;
x = game->map.x + (MSPEED * game->c[game->map.a]);
y = game->map.y + (MSPEED * game->s[game->map.a]);
if (game->map.lab[(int)x][(int)y] != '1')
{
game->map.x = x;
game->map.y = y;
vision_field(game);
}
if (game->map.lab[(int)x][(int)y] == '2')
level_two(&(game->map));
}
void down_move(s_move *game)
{
float x;
float y;
x = game->map.x - (MSPEED * game->c[game->map.a]);
y = game->map.y - (MSPEED * game->s[game->map.a]);
if (game->map.lab[(int)x][(int)y] != '1')
{
game->map.x = x;
game->map.y = y;
vision_field(game);
}
if (game->map.lab[(int)x][(int)y] == '2')
level_two(&(game->map));
}
void left_move(s_move *game)
{
game->map.a = (game->map.a + RSPEED) % 360;
vision_field(game);
}
void right_move(s_move *game)
{
game->map.a = game->map.a - RSPEED;
if (game->map.a < 0)
game->map.a = 360 + game->map.a;
vision_field(game);
}
int key_touch(int key, s_move *game)
{
void (*move[4])(s_move*);
if (key == 65307)
{
mlx_destroy_window(game->win.mlx_ptr, game->win.win_ptr);
exit(0);
}
move[0] = &left_move;
move[1] = &up_move;
move[2] = &right_move;
move[3] = &down_move;
if (KEY(key) >= 0 && KEY(key) <= 3)
move[KEY(key)](game);
return (0);
}