Project

General

Profile

Revision 228

bullet gunner collision

View differences:

proj/include/ent.h
40 40
int    (map_collides_point)(const map_t *p, double x, double y);
41 41
int    (map_collides_gunner)(const map_t *p, const gunner_t *gunner);
42 42
int    (map_collides_bullet)(const map_t *p, const bullet_t *bullet);
43
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull);
43 44
void   (map_draw)(map_t *p);
44 45

  
45 46
#endif //ENT_H_INCLUDED
proj/src/ent.c
152 152
}
153 153

  
154 154
int (map_collides_gunner)(const map_t *p, const gunner_t *shooter) {
155
    double radius = sprite_get_w(shooter->dude)/2.0;
155
    double radius = max(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
156 156
    double shooter_x = gunner_get_x(shooter);
157 157
    double shooter_y = gunner_get_y(shooter);
158 158
    for (double x = -radius; x < radius; x += 1) {
......
175 175
    return 0;
176 176
}
177 177

  
178
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull){
179
    double shooter_radius = max(sprite_get_w(shooter->dude), sprite_get_h(shooter->dude))/2.0;
180
    double shooter_x = gunner_get_x(shooter);
181
    double shooter_y = gunner_get_y(shooter);
182

  
183
    double bullet_radius = max(sprite_get_w(bull->b), sprite_get_h(bull->b))/2.0;
184
    double bullet_x = bullet_get_x(bull);
185
    double bullet_y = bullet_get_y(bull);
186

  
187
    double dx = shooter_x - bullet_x;
188
    double dy = shooter_y - bullet_y;
189
    double distance = sqrt(dx*dx + dy*dy);
190
    return distance <= shooter_radius+bullet_radius;
191
}
192

  
178 193
void   (map_draw)(map_t *p){
179 194
    const int16_t x_screen = map_get_x_screen(p);
180 195
    const int16_t y_screen = map_get_y_screen(p);
proj/src/proj.c
179 179
                            if (i == 0) {
180 180
                                if (no_interrupts % refresh_count_value == 0) {
181 181
                                    update_movement(map1, shooter1);
182
                                    bullet_update_movement(bullet);
182
                                    //bullet_update_movement(bullet);
183 183

  
184 184
                                    if(map_collides_gunner(map1, shooter1)){
185 185
                                        printf("COLLIDING\n");
186 186
                                    }
187 187

  
188
                                    if (gunner_collides_bullet(shooter1, bullet)) {
189
                                        printf("Bullet Collide with Shooter\n");
190
                                    }
191

  
188 192
                                    update_scale();
189 193

  
190 194
                                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,

Also available in: Unified diff