コード例 #1
0
void SlimePetEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
    if (canCollide() && collideWithEntity(entity))
    {
        if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX_COUNT)
        {
            EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity);
            if (enemyEntity->canCollide())
            {
                if (attackDelay <= 0.0f)
                {
                    enemyEntity->hurt(getHurtParams(12, ShotTypeStandard,0, false, SourceTypeMelee, EnemyTypeNone,false));
                    attackDelay = 0.65f;

                    float xs = (x + enemyEntity->getX()) / 2;
                    float ys = (y + enemyEntity->getY()) / 2;
                    SpriteEntity* star = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_HURT_IMPACT), xs, ys);
                    star->setFading(true);
                    star->setZ(y+ 100);
                    star->setLifetime(0.7f);
                    star->setType(ENTITY_EFFECT);
                    star->setSpin(400.0f);
                }

                if (enemyEntity->getMovingStyle() == movWalking)
                {
                    Vector2D vel = Vector2D(enemyEntity->getX(), enemyEntity->getY()).vectorTo(Vector2D(x, y), 100.0f );
                    giveRecoil(false, vel, 0.3f);
                }
            }
        }
    }
}
コード例 #2
0
ファイル: SnakeEntity.cpp プロジェクト: LibreGames/witchblast
void SnakeEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
  if (!isDying && !isAgonising && collideWithEntity(entity))
  {
    if (entity->getType() == ENTITY_PLAYER || entity->getType() == ENTITY_BOLT )
    {
      PlayerEntity* playerEntity = dynamic_cast<PlayerEntity*>(entity);
      BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity);

      if (playerEntity != NULL && !playerEntity->isDead())
      {
        int meleeLevel = 0;
        if (snakeType == SnakeTypeBlood)
        {
          if (rand() % 3 == 0)
          {
            meleeType = ShotTypePoison;
            meleeDamages = 4;
            meleeLevel = 1;
          }
          else
          {
            meleeType = ShotTypeStandard;
            meleeDamages = 8;
          }
        }
        if (playerEntity->hurt(getHurtParams(meleeDamages, meleeType, meleeLevel, false, SourceTypeMelee, enemyType, false)))
        {
          float xs = (x + playerEntity->getX()) / 2;
          float ys = (y + playerEntity->getY()) / 2;
          SpriteEntity* star = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_HURT_IMPACT), xs, ys);
          star->setFading(true);
          star->setZ(y+ 100);
          star->setLifetime(0.7f);
          star->setType(ENTITY_EFFECT);
          star->setSpin(400.0f);
        }
        inflictsRecoilTo(playerEntity);
      }

      else if (boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f)
      {
        collideWithBolt(boltEntity);
      }
    }
    else // collision with other enemy ?
    {
      if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX_COUNT)
      {
        if (this != entity)
        {
          EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity);
          if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity);
        }
      }
    }
  }
}
コード例 #3
0
void BaseCreatureEntity::generateStar(sf::Color starColor)
{
  SpriteEntity* spriteStar = new SpriteEntity(
                           ImageManager::getInstance().getImage(IMAGE_STAR_2),
                            x, y);
  spriteStar->setScale(0.8f, 0.8f);
  spriteStar->setZ(z-1.0f);
  spriteStar->setLifetime(0.8f);
  spriteStar->setSpin(-100 + rand()%200);
  spriteStar->setVelocity(Vector2D(10 + rand()%40));
  spriteStar->setWeight(-150);
  spriteStar->setFading(true);
  spriteStar->setColor(starColor);
  spriteStar->setType(ENTITY_EFFECT);
}
コード例 #4
0
void LargeSlimeEntity::dying()
{
  isDying = true;
  game().addKilledEnemy(enemyType, hurtingType);
  if (slimeType == SlimeTypeBlue) game().addCorpse(x, y, FRAME_CORPSE_GIANT_SLIME_BLUE);
  else if (slimeType == SlimeTypeRed) game().addCorpse(x, y, FRAME_CORPSE_GIANT_SLIME_RED);
  else if (slimeType == SlimeTypeStandard) game().addCorpse(x, y, FRAME_CORPSE_GIANT_SLIME);

  float xSlime = x;
  float ySlime = y;

  if (x <= 1.5 * TILE_WIDTH) x = 1.5f * TILE_WIDTH + 2;
  else if (x >= TILE_WIDTH * MAP_WIDTH - 1.5f * TILE_WIDTH) x = TILE_WIDTH * MAP_WIDTH - 1.5f * TILE_WIDTH -3;
  if (y <= 1.5 * TILE_HEIGHT) y = 1.5 * TILE_HEIGHT + 2;
  else if (y >= TILE_HEIGHT * MAP_HEIGHT - 1.5f * TILE_HEIGHT) y = TILE_HEIGHT * MAP_HEIGHT - 1.5f * TILE_HEIGHT -3;

  for (int i = 0; i < 9; i++)
  {
    game().generateBlood(xSlime, ySlime, bloodColor);
    if (i % 2 == 0)
    {
      switch (slimeType)
      {
        case SlimeTypeBlue: new SlimeEntity(x, y, SlimeTypeBlue, true); break;
        case SlimeTypeRed: new SlimeEntity(x, y, SlimeTypeRed, true); break;
        case SlimeTypeViolet: new SlimeEntity(x, y, SlimeTypeViolet, true); break;
        default: new SlimeEntity(x, y, SlimeTypeStandard, true); break;
      }
    }
  }

  game().makeShake(1.0f);
  SoundManager::getInstance().playSound(SOUND_SLIME_SMASH);

  ItemEntity* newItem = new ItemEntity(ItemSilverCoin, x, y);
  newItem->setVelocity(Vector2D(100.0f + rand()% 250));
  newItem->setViscosity(0.96f);

  SpriteEntity* star = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_GIANT_SLIME), x, y, 128, 128, 8);
  star->setFrame(4);
  star->setFading(true);
  star->setZ(y+ 100);
  star->setAge(-0.4f);
  star->setLifetime(0.3f);
  star->setType(ENTITY_EFFECT);
  star->setSpin(400.0f);
}
コード例 #5
0
ファイル: ChestEntity.cpp プロジェクト: qw3ry/witchblast
void ChestEntity::generateStar(sf::Color starColor)
{
  SpriteEntity* spriteStar = new SpriteEntity(
                           ImageManager::getInstance().getImage(IMAGE_STAR_2),
                            x - 15 + rand() % 30, y - 10 + rand() % 30);
  spriteStar->setScale(0.8f, 0.8f);
  spriteStar->setZ(1000.0f);
  spriteStar->setSpin(-100 + rand()%200);
  spriteStar->setVelocity(Vector2D(50 + rand()%40));
  spriteStar->setWeight(-130);
  spriteStar->setFading(true);
  spriteStar->setAge(-0.8f);
  spriteStar->setLifetime(0.2f + (rand() % 100) * 0.005f );
  spriteStar->setColor(starColor);
  spriteStar->setType(ENTITY_EFFECT);
  spriteStar->setRenderAdd();
}
コード例 #6
0
void GiantSlimeEntity::dying()
{
  isDying = true;
  game().addKilledEnemy(enemyType, hurtingType);
  game().addCorpse(x, y, FRAME_CORPSE_GIANT_SLIME);

  float xSlime = x;
  float ySlime = y;

  if (x <= 1.5 * TILE_WIDTH) x = 1.5f * TILE_WIDTH + 2;
  else if (x >= TILE_WIDTH * MAP_WIDTH - 1.5f * TILE_WIDTH) x = TILE_WIDTH * MAP_WIDTH - 1.5f * TILE_WIDTH -3;
  if (y <= 1.5 * TILE_HEIGHT) y = 1.5 * TILE_HEIGHT + 2;
  else if (y >= TILE_HEIGHT * MAP_HEIGHT - 1.5f * TILE_HEIGHT) y = TILE_HEIGHT * MAP_HEIGHT - 1.5f * TILE_HEIGHT -3;

  for (int i = 0; i < 9; i++)
  {
    game().generateBlood(xSlime, ySlime, bloodColor);
    SlimeEntity* slime = new SlimeEntity(x, y, SlimeTypeStandard, true);
    slime->disableCollidingTemporary();
  }

  game().makeShake(1.0f);
  SoundManager::getInstance().playSound(SOUND_SLIME_SMASH);

  ItemEntity* newItem = new ItemEntity(ItemBossHeart, x, y);
  newItem->setVelocity(Vector2D(100.0f + rand()% 250));
  newItem->setViscosity(0.96f);

  SpriteEntity* star = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_GIANT_SLIME), x, y, 128, 128, 8);
  star->setFrame(4);
  star->setFading(true);
  star->setZ(y+ 100);
  star->setAge(-0.4f);
  star->setLifetime(0.3f);
  star->setType(ENTITY_EFFECT);
  star->setSpin(400.0f);
}
コード例 #7
0
void CauldronEntity::animate(float delay)
{
  if (isAgonising)
  {
    agonizingDelay -= delay;
    if (agonizingDelay <= 0.0f)
    {
      isDying = true;
      game().addCorpse(x, y, deathFrame);
    }
  }
  else
  {
    SoundManager::getInstance().playSound(SOUND_CAULDRON, false);

    invokeDelay -= delay;
    if (invokeDelay < 0.0f)
    {
      if (cauldronType == CauldronTypeElemental)
      {
        if (game().getEnemyCount() < 9)
        {
          slimeTypeEnum slimeType = SlimeTypeStandard;
          switch (colorState)
          {
            case 0: slimeType = SlimeTypeBlue; break;
            case 1: slimeType = SlimeTypeRed; break;
            case 2: slimeType = SlimeTypeStandard; break;
          }
          SlimeEntity* slime = new SlimeEntity(x, y, slimeType, true);
          slime->disableCollidingTemporary();
          invokeDelay = 3.75f + (float)(rand() % 3000) / 1000.0f;
        }
      }
      else
      {
        SlimeEntity* slime = new SlimeEntity(x, y, SlimeTypeViolet, true);
        slime->disableCollidingTemporary();
        invokeDelay = 1.5f + (float)(rand() % 2500) / 1000.0f;
      }
    }

    if (cauldronType == CauldronTypeElemental)
    {
      colorChangeDelay -= delay;
      if (colorChangeDelay < 0.0f)
      {
        colorChangeDelay = 4.0f + rand()% 50 * 0.1f;
        if (rand() % 2 == 0)
        {
          colorState++;
          if (colorState > 2) colorState = 0;
        }
        else
        {
          colorState--;
          if (colorState < 0) colorState = 2;
        }
      }
    }

    bubbleDelay -= delay;
    if (bubbleDelay < 0.0f)
    {
      bubbleDelay = 0.3f;
      int bubbleFrame = 32;
      if (cauldronType == CauldronTypeElemental)
      {
        switch (colorState)
        {
          case 0: bubbleFrame = 33; break;
          case 1: bubbleFrame = 34; break;
          case 2: bubbleFrame = 35; break;
        }
      }

      for (int i=0; i < 2; i++)
      {
        float xBub = x - 16 + rand() % 32;
        SpriteEntity* bubble = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_CAULDRON), xBub, y - 20, 8, 8);
        bubble->setZ(z);
        bubble->setFrame(bubbleFrame);
        bubble->setType(ENTITY_EFFECT);
        bubble->setWeight(-20 - rand() % 40);
        bubble->setLifetime(2.0f);
        float bloodScale = 0.3f + (rand() % 20) * 0.1f;
        bubble->setScale(bloodScale, bloodScale);
      }
    }
    frame = hp > hpMax / 2 ? 0 : 1;
    if (cauldronType == CauldronTypeElemental)
    {
      switch (colorState)
      {
        case 0: frame += 2; break;
        case 1: frame += 4; break;
        case 2: frame += 6; break;
      }
    }

    EnemyEntity::animate(delay);
  }
}