Project

General

Profile

Revision 324

corrected some more things

View differences:

proj_func.c
65 65
    free(p);
66 66
}
67 67

  
68
remote_info_t* remote_info_ctor() {
68
remote_info_t* remote_info_ctor(void) {
69 69
    remote_info_t *ret = (remote_info_t*)malloc(sizeof(remote_info_t));
70 70
    if (ret == NULL) return ret;
71 71

  
......
81 81
    free(p);
82 82
}
83 83

  
84
bullet_info_t* bullet_info_ctor() {
84
bullet_info_t* bullet_info_ctor(void) {
85 85
    bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t));
86 86
    if (ret == NULL) return ret;
87 87

  
......
117 117
}
118 118

  
119 119
void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) {
120
    int ver_mov = keys->s_pressed - keys->w_pressed;
121
    int hor_mov = keys->d_pressed - keys->a_pressed;
122
    double x = gunner_get_x(p);
123
    double y = gunner_get_y(p);
120
    /** Player movement */{
121
        int ver_mov = keys->s_pressed - keys->w_pressed;
122
        int hor_mov = keys->d_pressed - keys->a_pressed;
123
        double x = gunner_get_x(p);
124
        double y = gunner_get_y(p);
124 125

  
125
    gunner_set_pos(p, x + SHOOTER_SPEED * hor_mov, y);
126
    if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y);
127
    else {
128
        list_node_t *it = list_begin(shooter_list);
129
        while (it != list_end(shooter_list)) {
130
            gunner_t *p2 = *(gunner_t**)list_node_val(it);
131
            if (p != p2 && gunner_collides_gunner(p, p2)) {
132
                gunner_set_pos(p, x, y);
133
                break;
126
        gunner_set_pos(p, x + SHOOTER_SPEED * hor_mov, y);
127
        if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y);
128
        else {
129
            list_node_t *it = list_begin(shooter_list);
130
            while (it != list_end(shooter_list)) {
131
                gunner_t *p2 = *(gunner_t**)list_node_val(it);
132
                if (p != p2 && gunner_collides_gunner(p, p2)) {
133
                    gunner_set_pos(p, x, y);
134
                    break;
135
                }
136
                it = list_node_next(it);
134 137
            }
135
            it = list_node_next(it);
136 138
        }
137
    }
138
    x = gunner_get_x(p);
139
    gunner_set_pos(p, x, y + SHOOTER_SPEED * ver_mov);
140
    if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y);
141
    else {
142
        list_node_t *it = list_begin(shooter_list);
143
        while (it != list_end(shooter_list)) {
144
            gunner_t *p2 = *(gunner_t**)list_node_val(it);
145
            if (p != p2 && gunner_collides_gunner(p, p2)) {
146
                gunner_set_pos(p, x, y);
147
                break;
139
        x = gunner_get_x(p);
140
        gunner_set_pos(p, x, y + SHOOTER_SPEED * ver_mov);
141
        if (map_collides_gunner(map, p)) gunner_set_pos(p, x, y);
142
        else {
143
            list_node_t *it = list_begin(shooter_list);
144
            while (it != list_end(shooter_list)) {
145
                gunner_t *p2 = *(gunner_t**)list_node_val(it);
146
                if (p != p2 && gunner_collides_gunner(p, p2)) {
147
                    gunner_set_pos(p, x, y);
148
                    break;
149
                }
150
                it = list_node_next(it);
148 151
            }
149
            it = list_node_next(it);
150 152
        }
151 153
    }
152

  
153
    // Update zombie positions
154
    list_node_t *it = list_begin(shooter_list);
155
    while(it != list_end(shooter_list)){
156
        gunner_t *g = *(gunner_t**)list_node_val(it);
157
        if(gunner_get_type(g) & GUNNER_FOLLOW){
158
            double theta = 0.0;
159
            map_where_to_follow(map, gunner_get_x(g), gunner_get_y(g), &theta);
160
            double c = fm_cos(theta), s = fm_sin(theta);
161
            double dx = ZOMBIE_SPEED*c, dy = -ZOMBIE_SPEED*s;
162
            double x = gunner_get_x(g);
163
            double y = gunner_get_y(g);
164
            gunner_set_pos(g, x+dx, y+dy);
165
            if (map_collides_gunner(map, g)){
166
                //printf("Zombie colliding with map\n");
167
                gunner_set_pos(g, x, y);
168
            } else {
169
                list_node_t *it = list_begin(shooter_list);
170
                while (it != list_end(shooter_list)) {
171
                    gunner_t *p2 = *(gunner_t**)list_node_val(it);
172
                    if (g != p2 && gunner_collides_gunner(g, p2)) {
173
                        //printf("Zombie colliding with zombie\n");
174
                        gunner_set_pos(g, x, y);
175
                        break;
154
    /** Followers movement */ {
155
        list_node_t *it = list_begin(shooter_list);
156
        while(it != list_end(shooter_list)){
157
            gunner_t *g = *(gunner_t**)list_node_val(it);
158
            if(gunner_get_type(g) & GUNNER_FOLLOW){
159
                double theta = 0.0;
160
                map_where_to_follow(map, gunner_get_x(g), gunner_get_y(g), &theta);
161
                double c = fm_cos(theta), s = fm_sin(theta);
162
                double dx = ZOMBIE_SPEED*c, dy = -ZOMBIE_SPEED*s;
163
                double x = gunner_get_x(g);
164
                double y = gunner_get_y(g);
165
                gunner_set_pos(g, x+dx, y+dy);
166
                if (map_collides_gunner(map, g)){
167
                    gunner_set_pos(g, x, y);
168
                } else {
169
                    list_node_t *it2 = list_begin(shooter_list);
170
                    while (it2 != list_end(shooter_list)) {
171
                        gunner_t *p2 = *(gunner_t**)list_node_val(it2);
172
                        if (g != p2 && gunner_collides_gunner(g, p2)) {
173
                            gunner_set_pos(g, x, y);
174
                            break;
175
                        }
176
                        it2 = list_node_next(it2);
176 177
                    }
177
                    it = list_node_next(it);
178 178
                }
179
                gunner_set_angle(g, theta-M_PI_2);
179 180
            }
180
            gunner_set_angle(g, theta-M_PI_2); /*printf("angle: %d.%d\n", (int)theta, abs((int)(theta*1000)%1000));*/
181
            it = list_node_next(it);
181 182
        }
182
        it = list_node_next(it);
183 183
    }
184 184
}
185 185

  
......
298 298

  
299 299
void (update_mouse)(struct packet *p) {
300 300
    mouse_x = max16(0, mouse_x + p->delta_x);
301
    mouse_x = min16(mouse_x, graph_get_XRes() - 1);
301
    mouse_x = min16(mouse_x, (int16_t)graph_get_XRes() - 1);
302 302

  
303 303
    mouse_y = max16(0, mouse_y - p->delta_y);
304
    mouse_y = min16(mouse_y, graph_get_YRes() - 1);
304
    mouse_y = min16(mouse_y, (int16_t)graph_get_YRes() - 1);
305 305

  
306 306
    key_presses.lb_pressed = p->lb;
307 307
}

Also available in: Unified diff