예제 #1
0
/*************************************************
 * handles when objects hit each other
 *************************************************/
float Velocity::minimumDistance(Velocity a, Velocity  b)
{
   
   float distanceSquared;
   float minDist;
   float slice = 1 / (max(max(a.getDx(), a.getDy()   ),
                         max(b.getDx(), b.getDy())  ));
   for (float percent = 0; percent <= 100; slice++)
   {
      float distaceSquared = ((a.getX() + a.getDx() * percent) - pow((b.getX() + b.getDx() * percent),2)) +
         ((a.getY() + a.getDy() * percent) - pow((b.getY() + b.getDy() * percent),2) );
      float minDist = min(distanceSquared, minDist);
   }

   return sqrt(minDist);
}
예제 #2
0
/**********************************************************
 * SMALLROCK constructor
 ***********************************************************/
SmallRock :: SmallRock(Velocity biggerV)
{
   setPoint(biggerV.getX(), biggerV.getY());

   v.setDx(random(-SM_SPEED, SM_SPEED));
   v.setDy(random(-SM_SPEED, SM_SPEED));
   v += biggerV;
}
예제 #3
0
/**********************************************************
 * MEDIUMROCK constructor
 ***********************************************************/
MediumRock :: MediumRock(Velocity bigV)
{
   setPoint(bigV.getX(), bigV.getY());
   
   v.setDx(random(-MED_SPEED, MED_SPEED));
   v.setDy(random(-MED_SPEED, MED_SPEED));
   v += bigV;
}