Project

General

Profile

Revision 309

finally done with zombies!

View differences:

proj_func.c
83 83
    }
84 84

  
85 85
    // Update zombie positions
86
    map_make_dijkstra(map, gunner_get_x(p), gunner_get_y(p));
87 86
    list_node_t *it = list_begin(shooter_list);
88 87
    while(it != list_end(shooter_list)){
89 88
        gunner_t *g = *(gunner_t**)list_node_val(it);
90 89
        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

  
90
            float theta = 0.0;
91
            map_where_to_follow(map, gunner_get_x(g), gunner_get_y(g), &theta);
92
            float c = fm_cos(theta), s = fm_sin(theta);
93
            float dx = ZOMBIE_SPEED*c, dy = -ZOMBIE_SPEED*s;
94
            double x = gunner_get_x(g);
95
            double y = gunner_get_y(g);
96
            gunner_set_pos(g, x+dx, y+dy);
97
            if (map_collides_gunner(map, g)){
98
                //printf("Zombie colliding with map\n");
99
                gunner_set_pos(g, x, y);
100
            } else {
101
                list_node_t *it = list_begin(shooter_list);
102
                while (it != list_end(shooter_list)) {
103
                    gunner_t *p2 = *(gunner_t**)list_node_val(it);
104
                    if (g != p2 && gunner_collides_gunner(g, p2)) {
105
                        //printf("Zombie colliding with zombie\n");
106
                        gunner_set_pos(g, x, y);
107
                        break;
108
                    }
109
                    it = list_node_next(it);
110
                }
111
            }
112
            gunner_set_angle(g, theta-M_PI_2); /*printf("angle: %d.%d\n", (int)theta, abs((int)(theta*1000)%1000));*/
95 113
        }
96 114
        it = list_node_next(it);
97 115
    }

Also available in: Unified diff