Просмотр исходного кода

fix colision particle vs scientist

Tim Strasser 2 лет назад
Родитель
Сommit
b172973292
1 измененных файлов с 8 добавлено и 11 удалено
  1. 8 11
      includes/particle.c

+ 8 - 11
includes/particle.c

@@ -13,19 +13,16 @@ void particle_tick(PARTICLE* const particles, SCIENTIST* const scientists, int*
             // Check collision with scientists
             for(int j = 0; j < SCIENTISTS_MAX; j++) {
                 if(scientists[j].state == ScientistStateAlive && scientists[j].point.x > 0) {
-                    // Added half the width and height of the scientist sprite to the scientist's x and y respectively
-                    float scientist_center_x = scientists[j].point.x + 5.5;
-                    float scientist_center_y = scientists[j].point.y + 7.5;
+                    // Check whether the particle lies within the scientist's bounding box
                     if(!(particles[i].point.x >
-                             scientist_center_x +
-                                 5.5 || // particle is to the right of the scientist
-                         particles[i].point.x + 11 <
-                             scientist_center_x -
-                                 5.5 || // particle is to the left of the scientist
+                             scientists[j].point.x +
+                                 9 || // particle is to the right of the scientist
+                         particles[i].point.x <
+                             scientists[j].point.x || // particle is to the left of the scientist
                          particles[i].point.y >
-                             scientist_center_y + 7.5 || // particle is below the scientist
-                         particles[i].point.y + 15 <
-                             scientist_center_y - 7.5)) { // particle is above the scientist
+                             scientists[j].point.y + 14 || // particle is below the scientist
+                         particles[i].point.y <
+                             scientists[j].point.y)) { // particle is above the scientist
                         scientists[j].state = ScientistStateDead;
                         (*points) += 2; // Increase the score by 2
                     }