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
|
#include "../game/game.h"
enum direction last_player_move;
void move_player(enum direction dir)
{
int x, y;
x = y = 0;
dir_to_xy(dir, &x, &y);
last_player_move = dir;
move(&player, x, y);
}
static void move_up()
{
move_player(UP);
}
static void move_left()
{
move_player(LEFT);
}
static void move_down()
{
move_player(DOWN);
}
static void move_right()
{
move_player(RIGHT);
}
__attribute__((constructor)) static void init()
{
register_input_handler('w', (struct input_handler) {
.run_if_dead = false,
.callback = &move_up,
});
register_input_handler('a', (struct input_handler) {
.run_if_dead = false,
.callback = &move_left,
});
register_input_handler('s', (struct input_handler) {
.run_if_dead = false,
.callback = &move_down,
});
register_input_handler('d', (struct input_handler) {
.run_if_dead = false,
.callback = &move_right,
});
}
|