Exemplo n.º 1
0
//==============================================================================
bool Joint::checkSanity(bool _printWarnings) const
{
  bool sane = true;
  for(std::size_t i=0; i < getNumDofs(); ++i)
  {
    if(getInitialPosition(i) < getPositionLowerLimit(i)
       || getPositionUpperLimit(i) < getInitialPosition(i))
    {
      if(_printWarnings)
      {
        dtwarn << "[Joint::checkSanity] Initial position of index " << i << " ["
               << getDofName(i) << "] in Joint [" << getName() << "] is "
               << "outside of its position limits\n"
               << " -- Initial Position: " << getInitialPosition(i) << "\n"
               << " -- Limits: [" << getPositionLowerLimit(i) << ", "
               << getPositionUpperLimit(i) << "]\n";
      }
      else
      {
        return false;
      }

      sane = false;
    }

    if(getInitialVelocity(i) < getVelocityLowerLimit(i)
       || getVelocityUpperLimit(i) < getInitialVelocity(i))
    {
      if(_printWarnings)
      {
        dtwarn << "[Joint::checkSanity] Initial velocity of index " << i << " ["
               << getDofName(i) << "] is Joint [" << getName() << "] is "
               << "outside of its velocity limits\n"
               << " -- Initial Velocity: " << getInitialVelocity(i) << "\n"
               << " -- Limits: [" << getVelocityLowerLimit(i) << ", "
               << getVelocityUpperLimit(i) << "]\n";
      }
      else
      {
        return false;
      }

      sane = false;
    }
  }

  return sane;
}
Exemplo n.º 2
0
void System::ShootingSystem::update(int elapsedMs, World &world, Room &room)
{
    for(auto entity : world.getEntitiesForType(ComponentTypes::CANSHOOT))
    {
        CanShoot *c = (CanShoot *) entity->getComponent(ComponentTypes::CANSHOOT);
        Ammo *ammo = (Ammo *) entity->getComponent(ComponentTypes::AMMO);
        if(ammo == nullptr) {
            continue;
        }
        if(ammo->ammo == 0) {
            continue;
        }
        if(world.wasKeyPressed(SDLK_SPACE))
        {
            //TODO: Invert this if.
            if(c->currentMs == 0 || c->currentMs >= c->msBetweenShots) {
                ammo->ammo--;
                c->currentMs = 0;
                EntityFactory factory = EntityFactory();

                Position *initialPosition = new Position();
                Position *p = (Position *)entity->getComponent(ComponentTypes::POSITION);
                initialPosition->x = p->x;
                initialPosition->y = p->y;

                Entity *bullet = factory.createBullet(initialPosition, getInitialVelocity(entity));

                world.addEntity(bullet);
                engine->getSoundEngine()->playSound("Shoot.wav", 1);

            }
            c->currentMs += elapsedMs;
        }

    }
}