コード例 #1
0
ファイル: spritecache.cpp プロジェクト: yeKcim/warmux
Surface SpriteSubframeCache::GetSurfaceForAngle(Double angle)
{
  ASSERT(max - min > ZERO);
  //Double fmin = PI-max;
  angle = RestrictAngle(angle);
  uint index = ((uint)rotated.size()*angle - min) / Double(max-min);
  ASSERT(rotated.size()>index);

  // On demand-cache
  if (rotated[index].IsNull()) {
    angle = min + (max-min)*(1-index/(Double)rotated.size());
    rotated[index] = surface.RotoZoomC(angle, ONE, ONE, true);
  }
  return rotated[index];
}
コード例 #2
0
ファイル: spritecache.cpp プロジェクト: Arnaud474/Warmux
Surface SpriteSubframeCache::GetSurfaceForAngle(Double angle)
{
  ASSERT(max - min > ZERO);
  //Double fmin = PI-max;
  angle = RestrictAngle(angle);
  uint index = ((uint)rotated.size()*angle - min) / Double(max-min);
  ASSERT(rotated.size()>index);

  // On demand-cache
  if (rotated[index].IsNull()) {
    // Some compilers (old gccs?) need the explicit size_t->uint cast here
    angle = min + (max-min)*(1-index/(Double)uint(rotated.size()));
    rotated[index] = surface.RotoZoomC(angle, ONE, ONE);
  }
  return rotated[index];
}
コード例 #3
0
ファイル: polecat.cpp プロジェクト: Arnaud474/Warmux
void Polecat::Refresh()
{
  if (m_energy == 0) {
    Explosion();
    return;
  }
  int tmp = GetMSSinceTimeoutStart();
  if (cfg.timeout && tmp > 1000 * (GetTotalTimeout())) {
    if (!last_fart_time) {
      std::string txt = Format(_("%s has done something for the environment, he has not ordered the polecat to fart."),
             ActiveCharacter().GetName().c_str());
      Weapon::Message(txt);
    }
    SignalTimeout();
  }

  Double norm, angle;
  if (last_fart_time && last_fart_time + TIME_BETWEEN_FART < GameTime::GetInstance()->Read()) {
    Fart();
  }

  //When we hit the ground, jump !
  if(!IsMoving() && !FootsInVacuum()) {
    // Limiting number of rebound to avoid desync
    if(last_rebound_time + TIME_BETWEEN_REBOUND > GameTime::GetInstance()->Read()) {
      image->SetRotation_rad(0.0);
      return;
    }
    last_rebound_time = GameTime::GetInstance()->Read();
    MSG_DEBUG("weapon.polecat", "Jump ! (time = %d)", last_rebound_time);
    //If the GNU is stuck in ground -> change direction
    int x = GetX();
    int y = GetY();
    if(x == save_x && y == save_y)
      m_sens = -m_sens;
    save_x = x;
    save_y = y;

    //Do the jump
    norm = RandomSync().GetDouble(1.0, 2.0);
    PutOutOfGround();
    SetSpeedXY(Point2d(m_sens * norm , -norm * THREE));
  }
  //Due to a bug in the physic engine
  //sometimes, angle==infinite (according to gdb) ??
  GetSpeed(norm, angle);

  angle = RestrictAngle(angle) * ONE_HALF;
  bool flipped = m_sens == -1;
  if (flipped) {
    if (angle > 0)
      angle -= HALF_PI;
    else
      angle += HALF_PI;
  }

  image->SetRotation_rad(angle);
  image->SetFlipped(flipped);
  image->Scale(ONE, ONE);
  image->Update();
}