moved savelevel() code to level.h/c where it belongs to. :)
[supertux.git] / src / collision.c
index baa54ad..6e2a393 100644 (file)
 #include "bitmask.h"
 #include "scene.h"
 
-int rectcollision(itop_type* one, itop_type* two)
+int rectcollision(base_type* one, base_type* two)
 {
 
-  if (*one->x >= *two->x - *one->width &&
-      *one->x <= *two->x + *two->width  &&
-      *one->y >= *two->y - *one->height &&
-      *one->y <= *two->y + *two->height )
+  if (one->x >= two->x - one->width &&
+      one->x <= two->x + two->width  &&
+      one->y >= two->y - one->height &&
+      one->y <= two->y + two->height )
     {
       return YES;
     }
@@ -31,13 +31,13 @@ int rectcollision(itop_type* one, itop_type* two)
     }
 }
 
-int rectcollision_offset(itop_type* one, itop_type* two, float off_x, float off_y)
+int rectcollision_offset(base_type* one, base_type* two, float off_x, float off_y)
 {
 
-  if (*one->x >= *two->x - *one->width +off_x &&
-      *one->x <= *two->x + *two->width + off_x &&
-      *one->y >= *two->y - *one->height + off_y &&
-      *one->y <= *two->y + *two->height + off_y )
+  if (one->x >= two->x - one->width +off_x &&
+      one->x <= two->x + two->width + off_x &&
+      one->y >= two->y - one->height + off_y &&
+      one->y <= two->y + two->height + off_y )
     {
       return YES;
     }
@@ -47,45 +47,20 @@ int rectcollision_offset(itop_type* one, itop_type* two, float off_x, float off_
     }
 }
 
-void collision_rect_detect(int co_one, int co_two)
-{
-  int i,j;
-
-  /* CO_BULLET & CO_BADGUY check */
-  for(i = 0; i < NUM_BULLETS; ++i)
-    {
-      if(bullets[i].alive)
-        {
-          for(j = 0; j < NUM_BAD_GUYS; ++j)
-            {
-              if(bad_guys[j].alive)
-                {
-                  if(rectcollision(&bullets[i].it,&bad_guys[j].it) == YES)
-                    {
-                   /* We have detected a collision and now call the collision functions of the collided objects. */
-                     bullet_collision(&bullets[i], CO_BADGUY);
-                     badguy_collision(&bad_guys[j], &bullets[i], CO_BULLET);
-                    }
-                }
-            }
-        }
-    }
-}
-
 void collision_handler()
 {
   int i,j;
 
   /* CO_BULLET & CO_BADGUY check */
-  for(i = 0; i < NUM_BULLETS; ++i)
+  for(i = 0; i < num_bullets; ++i)
     {
-      if(bullets[i].alive)
+      if(bullets[i].base.alive)
         {
-          for(j = 0; j < NUM_BAD_GUYS; ++j)
+          for(j = 0; j < num_bad_guys; ++j)
             {
-              if(bad_guys[j].alive)
+              if(bad_guys[j].dying == NO && bad_guys[j].base.alive)
                 {
-                  if(rectcollision(&bullets[i].it,&bad_guys[j].it) == YES)
+                  if(rectcollision(&bullets[i].base,&bad_guys[j].base) == YES)
                     {
                    /* We have detected a collision and now call the collision functions of the collided objects. */
                      bullet_collision(&bullets[i], CO_BADGUY);
@@ -97,35 +72,36 @@ void collision_handler()
     }
     
     /* CO_BADGUY & CO_BADGUY check */
-  for(i = 0; i < NUM_BAD_GUYS; ++i)
+  for(i = 0; i < num_bad_guys; ++i)
     {
-      if(bad_guys[i].alive)
+      if(bad_guys[i].base.alive)
         {
-          for(j = i+1; j < NUM_BAD_GUYS; ++j)
+          for(j = i+1; j < num_bad_guys; ++j)
             {
-              if(j != i && bad_guys[j].alive)
+              if(j != i && bad_guys[j].base.alive)
                 {
-                  if(rectcollision(&bad_guys[i].it,&bad_guys[j].it) == YES)
+                  if(rectcollision(&bad_guys[i].base,&bad_guys[j].base) == YES)
                     {
                    /* We have detected a collision and now call the collision functions of the collided objects. */
                      badguy_collision(&bad_guys[j], &bad_guys[i], CO_BADGUY);
-                    }
+                     badguy_collision(&bad_guys[i], &bad_guys[j], CO_BADGUY);                    
+                   }
                 }
             }
         }
     }
 
     /* CO_BADGUY & CO_PLAYER check */
-  for(i = 0; i < NUM_BAD_GUYS; ++i)
+  for(i = 0; i < num_bad_guys; ++i)
     {
-      if(bad_guys[i].alive)
+      if(bad_guys[i].base.alive)
         {
-                 if(rectcollision_offset(&bad_guys[i].it,&tux.it,0,48) == YES && tux.ym < 0)
+                 if(bad_guys[i].dying == NO && rectcollision_offset(&bad_guys[i].base,&tux.base,0,0) == YES && tux.base.ym > 0)
                     {
                    /* We have detected a collision and now call the collision functions of the collided objects. */
                      badguy_collision(&bad_guys[i], &tux, CO_PLAYER);
                      }
-                  if(rectcollision(&bad_guys[i].it,&tux.it) == YES)
+                  if(rectcollision(&bad_guys[i].base,&tux.base) == YES)
                   {
                      player_collision(&tux, &bad_guys[i], CO_BADGUY);
                   }
@@ -134,11 +110,11 @@ void collision_handler()
     }
 
     /* CO_UPGRADE & CO_PLAYER check */
-  for(i = 0; i < NUM_UPGRADES; ++i)
+  for(i = 0; i < num_upgrades; ++i)
     {
-      if(upgrades[i].alive)
+      if(upgrades[i].base.alive)
         {
-                 if(rectcollision(&upgrades[i].it,&tux.it) == YES)
+                 if(rectcollision(&upgrades[i].base,&tux.base) == YES)
                     {
                    /* We have detected a collision and now call the collision functions of the collided objects. */
                      upgrade_collision(&upgrades[i], &tux, CO_PLAYER);