Project

General

Profile

Revision 246

convert to lists

View differences:

proj_func.c
48 48
    }
49 49
}
50 50

  
51

  
52
void update_movement(const map_t *map, gunner_t *p, gunner_t *p2) {
53
    int ver_mov = key_presses.s_pressed - key_presses.w_pressed;
54
    int hor_mov = key_presses.d_pressed - key_presses.a_pressed;
51
void update_movement(const map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) {
52
    int ver_mov = keys->s_pressed - keys->w_pressed;
53
    int hor_mov = keys->d_pressed - keys->a_pressed;
55 54
    double x = gunner_get_x(p);
56 55
    double y = gunner_get_y(p);
56

  
57 57
    gunner_set_pos(p, x + SHOOTER_SPEED * hor_mov, y);
58
    if (map_collides_gunner(map, p) || gunner_collides_gunner(p, p2)) {
59
        gunner_set_pos(p, x, y);
58
    if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y);
59
    else {
60
        list_node_t *it = list_begin(shooter_list);
61
        while (it != list_end(shooter_list)) {
62
            gunner_t *p2 = *(gunner_t**)list_node_val(it);
63
            if (p != p2 && gunner_collides_gunner(p, p2)) {
64
                gunner_set_pos(p, x, y);
65
                break;
66
            }
67
            it = list_node_next(it);
68
        }
60 69
    }
61
        x = gunner_get_x(p);
70
    x = gunner_get_x(p);
62 71
    gunner_set_pos(p, x, y + SHOOTER_SPEED * ver_mov);
63
    if (map_collides_gunner(map, p) || gunner_collides_gunner(p, p2)) {
64
        gunner_set_pos(p, x, y);
72
    if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y);
73
    else {
74
        list_node_t *it = list_begin(shooter_list);
75
        while (it != list_end(shooter_list)) {
76
            gunner_t *p2 = *(gunner_t**)list_node_val(it);
77
            if (p != p2 && gunner_collides_gunner(p, p2)) {
78
                gunner_set_pos(p, x, y);
79
                break;
80
            }
81
            it = list_node_next(it);
82
        }
65 83
    }
66 84
}
67 85

  
......
99 117
                /// Change health
100 118
                gunner_set_curr_health(shooter, gunner_get_curr_health(shooter) - bullet_get_damage(bullet));
101 119
                if (gunner_get_curr_health(shooter) <= 0) {
102
                    shooter = list_erase(shooter_list, shooter_it);
103
                    gunner_dtor(shooter);
120
                    gunner_set_curr_health(shooter, gunner_get_health(shooter));
121
                    get_random_spawn(map, shooter);
104 122
                }
105 123
                /// Delete bullet
106 124
                bullet_dtor(list_erase(bullet_list, bullet_it)); deleted_bullet = true;
......
115 133
    }
116 134
}
117 135

  
136
void (get_random_spawn)(const map_t *map, gunner_t *p) {
137
    uint16_t w = map_get_width(map), h = map_get_height(map);
138
    double x, y;
139

  
140
    do {
141
        x = rand() % w;
142
        y = rand() % h;
143
        gunner_set_pos(p, x, y);
144
    } while (map_collides_gunner(map, p));
145
}
146

  
118 147
void update_scale(void) {
119 148
    static uint8_t last_plus = 0, last_minus = 0;
120 149
    if (key_presses.ctrl_pressed) {

Also available in: Unified diff