]> git.lizzy.rs Git - dungeon_game.git/blob - plugins/movement/movement.c
Shoot fireballs into last movement direction
[dungeon_game.git] / plugins / movement / movement.c
1 #include "../game/game.h"
2
3 enum direction last_player_move;
4
5 void move_player(enum direction dir)
6 {
7         int x, y;
8         x = y = 0;
9
10         dir_to_xy(dir, &x, &y);
11         last_player_move = dir;
12
13         move(&player, x, y);
14 }
15
16 static void move_up()
17 {
18         move_player(UP);
19 }
20
21 static void move_left()
22 {
23         move_player(LEFT);
24 }
25
26 static void move_down()
27 {
28         move_player(DOWN);
29 }
30
31 static void move_right()
32 {
33         move_player(RIGHT);
34 }
35
36 __attribute__((constructor)) static void init()
37 {
38         register_input_handler('w', (struct input_handler) {
39                 .run_if_dead = false,
40                 .callback = &move_up,
41         });
42
43         register_input_handler('a', (struct input_handler) {
44                 .run_if_dead = false,
45                 .callback = &move_left,
46         });
47
48         register_input_handler('s', (struct input_handler) {
49                 .run_if_dead = false,
50                 .callback = &move_down,
51         });
52
53         register_input_handler('d', (struct input_handler) {
54                 .run_if_dead = false,
55                 .callback = &move_right,
56         });
57 }