root / proj / src / proj_func.c @ 192
History | View | Annotate | Download (1.97 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include "proj_func.h" |
4 |
|
5 |
#include "interrupts_func.h" |
6 |
#include "graph.h" |
7 |
#include "keyboard.h" |
8 |
#include "errors.h" |
9 |
#include "proj_macros.h" |
10 |
#include "utils.h" |
11 |
|
12 |
#include "kbc_macros.h" |
13 |
|
14 |
#include <math.h> |
15 |
|
16 |
int cleanup(void) { |
17 |
int r = SUCCESS;
|
18 |
if ((r = unsubscribe_all()))
|
19 |
printf("%s: failed to unsubscribe drivers.\n", __func__);
|
20 |
if ((r = graph_cleanup()))
|
21 |
printf("%s: graph cleanup failed\n", __func__);
|
22 |
|
23 |
return r;
|
24 |
} |
25 |
|
26 |
static int hor_mov = REST, ver_mov = REST; |
27 |
|
28 |
void update_key_presses(void) { |
29 |
static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0; |
30 |
if (sz == 1) { |
31 |
switch(scancode[0]) { |
32 |
case W_MAKE_CODE : w_pressed = 1; break; |
33 |
case W_BREAK_CODE : w_pressed = 0; break; |
34 |
case A_MAKE_CODE : a_pressed = 1; break; |
35 |
case A_BREAK_CODE : a_pressed = 0; break; |
36 |
case S_MAKE_CODE : s_pressed = 1; break; |
37 |
case S_BREAK_CODE : s_pressed = 0; break; |
38 |
case D_MAKE_CODE : d_pressed = 1; break; |
39 |
case D_BREAK_CODE : d_pressed = 0; break; |
40 |
} |
41 |
} |
42 |
ver_mov = s_pressed - w_pressed; |
43 |
hor_mov = d_pressed - a_pressed; |
44 |
} |
45 |
|
46 |
void update_movement(ent_t *p) {
|
47 |
static const int speed = 5; |
48 |
ent_set_pos(p, ent_get_x(p) + speed * hor_mov, ent_get_y(p) + speed * ver_mov); |
49 |
} |
50 |
|
51 |
static int32_t mouse_x = 0, mouse_y = 0; |
52 |
|
53 |
void update_mouse_position(struct packet *p) { |
54 |
mouse_x = max(0, mouse_x + p->delta_x);
|
55 |
mouse_x = min(mouse_x, graph_get_XRes() - 1);
|
56 |
|
57 |
mouse_y = max(0, mouse_y - p->delta_y);
|
58 |
mouse_y = min(mouse_y, graph_get_YRes() - 1);
|
59 |
} |
60 |
|
61 |
int32_t get_mouse_X(void) { return mouse_x; } |
62 |
|
63 |
int32_t get_mouse_Y(void) { return mouse_y; } |
64 |
|
65 |
double get_mouse_angle(ent_t *p) {
|
66 |
return atan2(ent_get_y_screen(p) - mouse_y, mouse_x - ent_get_x_screen(p));
|
67 |
} |
68 |
|
69 |
int get_hor_movement(void) { return hor_mov; } |
70 |
|
71 |
int get_ver_movement(void) { return ver_mov; } |