Project

General

Profile

Revision 200

zoom controls

View differences:

proj_func.c
8 8
#include "errors.h"
9 9
#include "proj_macros.h"
10 10
#include "utils.h"
11
#include "ent.h"
11 12

  
12 13
#include "kbc_macros.h"
13 14

  
......
24 25
}
25 26

  
26 27
static int hor_mov = REST, ver_mov = REST;
28
static keys_t key_presses;
27 29

  
28 30
void update_key_presses(void) {
29
    static int w_pressed = 0, a_pressed = 0, s_pressed = 0, d_pressed = 0;
30 31
    if (sz == 1) {
31 32
        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;
33
        case W_MAKE_CODE        : key_presses.w_pressed     = 1;        break;
34
        case W_BREAK_CODE       : key_presses.w_pressed     = 0;        break;
35
        case A_MAKE_CODE        : key_presses.a_pressed     = 1;        break;
36
        case A_BREAK_CODE       : key_presses.a_pressed     = 0;        break;
37
        case S_MAKE_CODE        : key_presses.s_pressed     = 1;        break;
38
        case S_BREAK_CODE       : key_presses.s_pressed     = 0;        break;
39
        case D_MAKE_CODE        : key_presses.d_pressed     = 1;        break;
40
        case D_BREAK_CODE       : key_presses.d_pressed     = 0;        break;
41
        case CTRL_MAKE_CODE     : key_presses.ctrl_pressed  = 1;        break;
42
        case CTRL_BREAK_CODE    : key_presses.ctrl_pressed  = 0;        break;
43
        case PLUS_MAKE_CODE     : key_presses.plus_pressed  = 1;        break;
44
        case PLUS_BREAK_CODE    : key_presses.plus_pressed  = 0;        break;
45
        case MINUS_MAKE_CODE    : key_presses.minus_pressed = 1;        break;
46
        case MINUS_BREAK_CODE   : key_presses.minus_pressed = 0;        break;
40 47
        }
41 48
    }
42
    ver_mov = s_pressed - w_pressed;
43
    hor_mov = d_pressed - a_pressed;
49
    ver_mov = key_presses.s_pressed - key_presses.w_pressed;
50
    hor_mov = key_presses.d_pressed - key_presses.a_pressed;
44 51
}
45 52

  
46 53
void update_movement(ent_t *p) {
......
48 55
    ent_set_pos(p, ent_get_x(p) + speed * hor_mov, ent_get_y(p) + speed * ver_mov);
49 56
}
50 57

  
58
void update_scale(void) {
59
    static uint8_t last_plus = 0, last_minus = 0;
60
    if (key_presses.ctrl_pressed) {
61
        if (key_presses.plus_pressed && !last_plus) {
62
            double scale = ent_get_scale();
63
            scale *= 1.1;
64
            if (scale <= MAX_SCALE) ent_set_scale(scale);
65
        }
66
        else if (key_presses.minus_pressed && !last_minus) {
67
            double scale = ent_get_scale();
68
            scale /= 1.1;
69
            if (scale >= MIN_SCALE) ent_set_scale(scale);
70
        }
71

  
72
        printf("SCALE: %d\n", (int)(ent_get_scale()*1000));
73
    }
74

  
75
    last_plus = key_presses.plus_pressed;
76
    last_minus = key_presses.minus_pressed;
77
}
78

  
51 79
static int32_t mouse_x = 0, mouse_y = 0;
52 80

  
53 81
void update_mouse_position(struct packet *p) {

Also available in: Unified diff