示例#1
0
/**********************************************************
 * SHIP :: interact()
 ***********************************************************/
void Ship :: interact(const Interface & pUI, void * asteroids)
{
   orientation += pUI.isLeft() * TURN_RADIUS;
   orientation -= pUI.isRight() * TURN_RADIUS;

   if (pUI.isUp())
   {
      thrustOn = true;
      Velocity thrust;
      thrust.setDx(THRUST *std::cos(deg2rad(orientation + 90)));
      thrust.setDy(THRUST * std::sin(deg2rad(orientation + 90)));
      v += thrust;
   }
   else
      thrustOn = false;
   
   if (pUI.isSpace())
   {
      Asteroids * pAsteroids = (Asteroids *)asteroids;
      pAsteroids->addItem(new Bullet(v, orientation));
      
   }

   
}
示例#2
0
Velocity operator+(const Velocity & lhs, const Velocity & rhs)
{
   // not a member or friend, so we need to use getters and setters

   Velocity sum;

   sum.setDx(lhs.getDx() + rhs.getDx());
   sum.setDy(lhs.getDy() + rhs.getDy());

   return sum;
}