Exemple #1
0
void ChestEntity::animate(float delay)
{
  CollidingSpriteEntity::animate(delay);
  if (!isOpen) testSpriteCollisions();
  z = y + height/2 - 5;

  // trap
  if (timer > 0.0f)
  {
    timer -= delay;
    if (timer <= 0.0f)
    {
      initFallingGrid();
      for (int i = 0; i < 22; i++) fallRock();
      SoundManager::getInstance().playSound(SOUND_TRAP);
      game().makeShake(0.25f);
    }
  }
}
Exemple #2
0
void ChestEntity::animate(float delay)
{
  if (appearTimer >= 0.0f) appearTimer -= delay;
  CollidingSpriteEntity::animate(delay);
  if (!isOpen) testSpriteCollisions();
  z = y + 21;

  // trap
  if (timer > 0.0f)
  {
    timer -= delay;
    if (timer <= 0.0f)
    {
      if (trap == TrapStones)
      {
        initFallingGrid();
        for (int i = 0; i < 22; i++) fallRock();
        game().makeShake(0.25f);
      }
      else if (trap == TrapExplosion)
      {
        initFallingGrid();
        new ExplosionEntity(x, y, ExplosionTypeStandard, 12, EnemyTypeNone, true);
        game().addCorpse(x, y, FRAME_CORPSE_SLIME_VIOLET);
        SoundManager::getInstance().playSound(SOUND_BOOM_00);
        game().makeShake(0.25f);
      }
      else // snakes
      {
        new SnakeEntity(x + 1, y, SnakeEntity::SnakeTypeNormal, false);
        new SnakeEntity(x - 1, y, SnakeEntity::SnakeTypeNormal, false);
        new SnakeEntity(x, y + 1, SnakeEntity::SnakeTypeNormal, false);
      }
    }
  }
}
void ObstacleEntity::animate(float delay)
{
  age += delay;
  testSpriteCollisions();
}
void SlimePetEntity::animate(float delay)
{
    if (age < 0.0f)
    {
        age += delay;
    }
    else
    {

        attackDelay -= delay;

        if (isJumping)
        {
            hVelocity -= 700.0f * delay;

            h += hVelocity * delay;

            bool firstTimeGround = false;

            if (h <= 0.0f)
            {
                h = 0.0f;
                if (isFalling())
                {
                    fall();
                }
                else
                {
                    if (isFirstJumping)
                    {
                        isFirstJumping = false;
                        firstTimeGround = true;
                        hVelocity = 160.0f;
                        SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT);
                    }
                    else
                    {
                        jumpingDelay = 0.3f + 0.1f * (rand() % 15);
                        isJumping = false;
                        SoundManager::getInstance().playSound(SOUND_SLIME_IMAPCT_WEAK);
                    }
                }
            }
            if (firstTimeGround) frame = 0;
            else if (hVelocity > -190.0f) frame = 2;
            else frame = 1;
        }
        else if (isFalling())
        {
            fall();
        }
        else
        {
            jumpingDelay -= delay;
            if (jumpingDelay < 0.0f)
            {
                SoundManager::getInstance().playSound(SOUND_SLIME_JUMP);
                hVelocity = 300.0f + rand() % 250;
                isJumping = true;
                isFirstJumping = true;

                float randVel = 250.0f + rand() % 250;

                setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), randVel ));
            }
            else if (jumpingDelay < 0.1f)
                frame = 1;
            else frame = 0;
        }

        BaseCreatureEntity::animate(delay);
        if (canCollide()) testSpriteCollisions();
    }

    z = y + 14;
}
Exemple #5
0
void CyclopsEntity::animate(float delay)
{
  if (age <= 0.0f)
  {
    age += delay;
    return;
  }

  if (isAgonising)
  {
    if (h < -0.01f)
    {
      isDying = true;
      game().addCorpse(x, y, deathFrame);
      if (dyingSound != SOUND_NONE) SoundManager::getInstance().playSound(dyingSound);
    }
    else
    {
      frame = dyingFrame;
      hVelocity -= 700.0f * delay;
      h += hVelocity * delay;
    }

    return;
  }

  // special states
  if (specialState[SpecialStateIce].active) delay *= specialState[SpecialStateIce].param1;

  // IA
  computeStates(delay);

  // collisions
  if (canCollide()) testSpriteCollisions();
  BaseCreatureEntity::animate(delay);

  // old frame (for sound)
  int oldFrame = frame;

  // current frame
  if (state == 0)
  {
    int r = ((int)(age * 5.0f)) % 4;
    if (r == 2) frame = 0;
    else if (r == 3) frame = 2;
    else frame = r;

    if (oldFrame == 1 && frame == 0) SoundManager::getInstance().playSound(SOUND_HEAVY_STEP_00);
    else if (oldFrame == 2 && frame == 0) SoundManager::getInstance().playSound(SOUND_HEAVY_STEP_01);
  }
  else if (state == 1)
  {
    isMirroring = game().getPlayer()->getX() > x;
    frame = timer > 0.5f ? 4 : 3;
  }
  else if (state == 2)
  {
    frame = 4;
  }
  else if (state == 3)
  {
    frame = 6;
  }
  else if (state == 4)
  {
    frame = 7;
  }

  // frame's mirroring
  if (velocity.x > 1.0f)
    isMirroring = true;
  else if (velocity.x < -1.0f)
    isMirroring = false;

  z = y + 36;
}
Exemple #6
0
void ItemEntity::animate(float delay)
{
  // Has been identified ?
  if (itemType >= ItemPotion01 && itemType < ItemPotion01 + NUMBER_UNIDENTIFIED)
  {
    if (game().potionEffectKnown(itemType))
    {
      itemType = game().getPotion(itemType);
      frame = itemType;
    }
  }
  // Has been forgotten
  else if (itemType >= ItemPotion01 + NUMBER_UNIDENTIFIED && itemType < FirstEquipItem)
  {
    if (!game().potionEffectKnown(itemType))
    {
      itemType = game().getPotion(itemType);
      frame = itemType;
    }
  }

  if (isMerchandise)
  {
    testSpriteCollisions();
    return;
  }

  if (isFlying)
  {
    if (!isCollidingWithMap() && isOnMap())
    {
      isFlying = false;
      viscosity = 0.96f;
    }
    else
    {
      if (velocity.x < -10 || velocity.x > 10 || velocity.y < -10 || velocity.y > 10) // moving
      {
        // stay in the map
        if (velocity.x < 40 && x < TILE_WIDTH) velocity.x = 220.0f;
        else if (velocity.x > -40 && x > (TILE_WIDTH - 1) * MAP_WIDTH) velocity.x = -220.0f;
        if (velocity.y < 40 && y < TILE_HEIGHT) velocity.y = 220.0f;
        else if (velocity.y > -40 && y > (TILE_HEIGHT - 1) * MAP_HEIGHT) velocity.y = -220.0f;
      }
      else // not moving
      {
        setVelocity(Vector2D(100.0f + rand()% 250));
      }
      // make move
      x += velocity.x * delay;
      y += velocity.y * delay;
      age += delay;
    }
  }
  else // not flying
  {
    if (isCollidingWithMap() || !isOnMap())
    {
      isFlying = true;
    }
    else
    {
      CollidingSpriteEntity::animate(delay);
      if (firstJump || (canBePickedUp() && !isMerchandise))
      {
        jumpTimer -= delay;
        firstJump = false;
        if (jumpTimer <= 0.0f)
        {
          jumpTimer = 2.0f + 0.1f * (rand() % 40);
          h = 0.1f;
          hVelocity = 150.0f;
        }
      }
    }
  }

  if (h > 0.0f)
  {
    h += hVelocity * delay;
    hVelocity -= 1200.0f * delay;
  }

  if (age > 0.7f) testSpriteCollisions();

  if (isBeating)
  {
    timer -= delay;
    if (timer <= 0.0f)
    {
      timer = HEART_BEAT_DELAY;
      SoundManager::getInstance().playSound(SOUND_HEART);
    }
    float sc;
    if (timer > HEART_BEAT_DELAY - 0.25f)
    {
      sc = timer - HEART_BEAT_DELAY + 1.25f;
    }
    else
      sc = 1.0f;
    sprite.setScale(sc, sc);
  }
  if (itemType == ItemBossHeart && !isBeating && game().getCurrentMap()->isCleared())
  {
    // start beating
    isBeating = true;
    timer = HEART_BEAT_DELAY;
  }

  z = y + height / 2;
}