Project

General

Profile

Revision 307

working on dijkstra for zombies

View differences:

proj_func.c
48 48
    }
49 49
}
50 50

  
51
void update_movement(const map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) {
51
void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) {
52 52
    int ver_mov = keys->s_pressed - keys->w_pressed;
53 53
    int hor_mov = keys->d_pressed - keys->a_pressed;
54 54
    double x = gunner_get_x(p);
......
81 81
            it = list_node_next(it);
82 82
        }
83 83
    }
84

  
85
    // Update zombie positions
86
    map_make_dijkstra(map, gunner_get_x(p), gunner_get_y(p));
87
    list_node_t *it = list_begin(shooter_list);
88
    while(it != list_end(shooter_list)){
89
        gunner_t *g = *(gunner_t**)list_node_val(it);
90
        if(gunner_get_type(g) & gunner_follow){
91
            //float theta = 0.0;
92
            //map_where_to_follow(map, &theta);
93
            //float c = fm_cos(theta), s = fm_sin(theta);
94

  
95
        }
96
        it = list_node_next(it);
97
    }
84 98
}
85 99

  
86 100
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet) {
......
138 152
        list_node_t *it2 = list_begin(shooter_list);
139 153
        while(it2 != list_end(shooter_list)){
140 154
            gunner_t *s2 = *list_node_val(it2);
141
            if(s1 != s2 && gunner_distance(s1, s2) < MELEE_RANGE)
155
            if(gunner_get_team(s1) != gunner_get_team(s2) &&
156
               gunner_distance(s1, s2) < MELEE_RANGE)
142 157
                gunner_set_curr_health(s2, gunner_get_curr_health(s2) - MELEE_DAMAGE);
143 158
            if(gunner_get_curr_health(s2) <= 0){
144 159
                list_node_t *aux = list_node_next(it2);
......
150 165
    }
151 166
}
152 167

  
153
void (get_random_spawn)(const map_t *map, gunner_t *p) {
168
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) {
154 169
    uint16_t w = map_get_width(map), h = map_get_height(map);
155 170
    double x, y;
156 171

  
157
    do {
172
    while(true){
158 173
        x = rand() % w;
159 174
        y = rand() % h;
160 175
        gunner_set_pos(p, x, y);
161
    } while (map_collides_gunner(map, p));
176
        if(map_collides_gunner(map, p)) continue;
177
        int collides = false;
178
        list_node_t *it = list_begin(l);
179
        while(it != list_end(l)){
180
            if(gunner_collides_gunner(p, *list_node_val(it))){
181
                collides = true;
182
                break;
183
            }
184
            it = list_node_next(it);
185
        }
186
        if(!collides) return;
187
    }
162 188
}
163 189

  
164 190
void update_scale(void) {

Also available in: Unified diff