Project

General

Profile

Revision 184

movement semi-implemented; missing structure

View differences:

proj/include/proj_func.h
10 10
 */
11 11
int cleanup(void);
12 12

  
13
void update_key_presses(void);
14

  
13 15
/**
14 16
 * @brief Updates movement variables.
15 17
 */
16
void update_movement(void);
18
void update_movement(sprite_t *p);
17 19

  
18 20
void update_mouse_position(struct packet *p);
19 21

  
proj/src/keyboard.c
39 39
    scancode[sz-1] = byte;
40 40
    done = !(TWO_BYTE_CODE == byte);
41 41

  
42
    if (done) update_movement();
42
    if (done) update_key_presses();
43 43

  
44 44
}
45 45

  
proj/src/proj.c
22 22

  
23 23
#ifdef TELMO
24 24
    #include "crosshair.h"
25
    #include "shooter.h"
25 26
#endif
26 27

  
27 28
int main(int argc, char* argv[]) {
......
116 117

  
117 118
    #ifdef TELMO
118 119
        sprite_t *crosshair = get_crosshair();
120
        sprite_t *shooter1 = get_shooter();
121
        sprite_set_pos(shooter1, 100, 100);
119 122
        graph_clear_screen();
120 123
        sprite_draw(crosshair);
124
        sprite_draw(shooter1);
121 125
        graph_draw();
122 126
    #endif
123 127

  
......
144 148
                            interrupt_handler(i);
145 149
                            if ((scancode[0]) == ESC_BREAK_CODE) good = 0;
146 150
                            #ifdef TELMO
151
                            update_movement(shooter1);
152
                            printf("POS: %d %d\n", sprite_get_x(shooter1), sprite_get_y(shooter1));
147 153
                            if (counter_mouse_ih >= 3) {
148 154
                                struct packet pp = mouse_parse_packet(packet_mouse_ih);
149 155
                                update_mouse_position(&pp);
150
                                sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
151 156
                                printf("X: %d | Y: %d | XRES: %d | YRES: %d\n", get_mouse_X(), get_mouse_Y(), graph_get_XRes(), graph_get_YRes());
157
                                counter_mouse_ih = 0;
158
                            }
159

  
160
                            sprite_set_pos(crosshair, get_mouse_X(), get_mouse_Y());
161
                            double angle = get_mouse_angle(shooter1);
162
                            sprite_set_angle(shooter1, angle);
152 163
                                graph_clear_screen();
153 164
                                sprite_draw(crosshair);
165
                                sprite_draw(shooter1);
154 166
                                graph_draw();
155
                                counter_mouse_ih = 0;
156
                            }
157 167
                            #endif
158 168
                        }
159 169
                    }
proj/src/proj_func.c
25 25

  
26 26
static int hor_mov = REST, ver_mov = REST;
27 27

  
28
void update_movement(void) {
28
void update_key_presses(void) {
29 29
    static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0;
30 30
    if (sz == 1) {
31 31
        switch(scancode[0]) {
......
43 43
    hor_mov = d_pressed - a_pressed;
44 44
}
45 45

  
46
void update_movement(sprite_t *p) {
47

  
48
    static const int speed = 5;
49
    sprite_set_pos(p, sprite_get_x(p) + speed * hor_mov, sprite_get_y(p) + speed * ver_mov);
50
}
51

  
46 52
static int32_t mouse_x = 0, mouse_y = 0;
47 53

  
48 54
void update_mouse_position(struct packet *p) {

Also available in: Unified diff