Project

General

Profile

Revision 228

bullet gunner collision

View differences:

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);

Also available in: Unified diff