Revision 171
crosshair and mouse (not working yet)
proj/xpm/crosshair.h | ||
---|---|---|
1 |
#include "crosshair.xpm" |
|
2 |
#include "sprite.h" |
|
3 |
|
|
4 |
sprite_t* get_crosshair(){ |
|
5 |
return sprite_ctor(crosshair_xpm, 0, 0); |
|
6 |
} |
|
0 | 7 |
proj/keyboard.c | ||
---|---|---|
20 | 20 |
int got_error_keyboard = SUCCESS; |
21 | 21 |
|
22 | 22 |
void (kbc_ih)(void) { |
23 |
if(done) { update_movement(); sz = 1; }
|
|
23 |
if(done) { sz = 1; } |
|
24 | 24 |
else sz++; |
25 | 25 |
uint8_t status = 0; |
26 | 26 |
got_error_keyboard = SUCCESS; |
... | ... | |
39 | 39 |
scancode[sz-1] = byte; |
40 | 40 |
done = !(TWO_BYTE_CODE == byte); |
41 | 41 |
|
42 |
if (done) update_movement(); |
|
42 | 43 |
|
43 | 44 |
} |
44 | 45 |
|
proj/proj.c | ||
---|---|---|
29 | 29 |
#include "shooter.h" |
30 | 30 |
#include "pistol.xpm" |
31 | 31 |
#endif |
32 |
#ifdef TELMO |
|
33 |
#include "crosshair.h" |
|
34 |
#endif |
|
32 | 35 |
|
33 | 36 |
int main(int argc, char* argv[]) { |
34 | 37 |
|
... | ... | |
78 | 81 |
sprite_dtor(shooter1); |
79 | 82 |
#endif |
80 | 83 |
|
84 |
#ifdef TELMO |
|
85 |
sprite_t *crosshair = get_crosshair(); |
|
86 |
graph_clear_screen(); |
|
87 |
sprite_draw(crosshair); |
|
88 |
graph_draw(); |
|
89 |
#endif |
|
90 |
|
|
81 | 91 |
/// loop stuff |
82 | 92 |
int ipc_status; |
83 | 93 |
message msg; |
... | ... | |
100 | 110 |
if (msg.m_notify.interrupts & n) { |
101 | 111 |
interrupt_handler(i); |
102 | 112 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
113 |
#ifdef TELMO |
|
114 |
if (counter_mouse_ih >= 3) { |
|
115 |
struct packet pp = mouse_parse_packet(packet_mouse_ih); |
|
116 |
update_mouse_position(&pp); |
|
117 |
sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y()); |
|
118 |
graph_clear_screen(); |
|
119 |
sprite_draw(crosshair); |
|
120 |
graph_draw(); |
|
121 |
} |
|
122 |
#endif |
|
103 | 123 |
} |
104 | 124 |
} |
105 | 125 |
|
proj/proj_func.c | ||
---|---|---|
28 | 28 |
void update_movement(void) { |
29 | 29 |
static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0; |
30 | 30 |
if (sz == 1) { |
31 |
kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode); |
|
32 | 31 |
switch(scancode[0]) { |
33 | 32 |
case W_MAKE_CODE : w_pressed = 1; break; |
34 | 33 |
case W_BREAK_CODE : w_pressed = 0; break; |
... | ... | |
44 | 43 |
hor_mov = d_pressed - a_pressed; |
45 | 44 |
} |
46 | 45 |
|
47 |
double get_mouse_angle(sprite_t *p, int32_t mouse_x, int32_t mouse_y) { |
|
46 |
static int32_t mouse_x = 0, mouse_y = 0; |
|
47 |
|
|
48 |
void update_mouse_position(struct packet *p) { |
|
49 |
mouse_x = max(0, mouse_x + p->delta_x); |
|
50 |
mouse_x = min(mouse_x, graph_get_XRes() - 1); |
|
51 |
|
|
52 |
mouse_y = max(0, mouse_y + p->delta_y); |
|
53 |
mouse_y = min(mouse_y, graph_get_YRes() - 1); |
|
54 |
} |
|
55 |
|
|
56 |
int32_t get_mouse_X(void) { return mouse_x; } |
|
57 |
|
|
58 |
int32_t get_mouse_Y(void) { return mouse_y; } |
|
59 |
|
|
60 |
double get_mouse_angle(sprite_t *p) { |
|
48 | 61 |
return atan2(sprite_get_y(p) - mouse_y, mouse_x - sprite_get_x(p)); |
49 | 62 |
} |
50 | 63 |
|
proj/proj_func.h | ||
---|---|---|
15 | 15 |
*/ |
16 | 16 |
void update_movement(void); |
17 | 17 |
|
18 |
void update_mouse_position(struct packet *p); |
|
19 |
|
|
20 |
int32_t get_mouse_X(void); |
|
21 |
|
|
22 |
int32_t get_mouse_Y(void); |
|
23 |
|
|
18 | 24 |
/** |
19 | 25 |
* @brief |
20 | 26 |
* @param |
... | ... | |
22 | 28 |
* @param |
23 | 29 |
* @return Angle |
24 | 30 |
*/ |
25 |
double get_mouse_angle(sprite_t *p, int32_t mouse_x, int32_t mouse_y);
|
|
31 |
double get_mouse_angle(sprite_t *p); |
|
26 | 32 |
|
27 | 33 |
/** |
28 | 34 |
* @brief Get horizontal movement direction. |
Also available in: Unified diff