Пример #1
0
void SausageEntity::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()) dying();

      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)
      {
        if (this != entity)
        {
          EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity);
          if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity);
        }
      }
    }
  }
}
Пример #2
0
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 SpiderWebEntity::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 (!isFromPlayer && playerEntity != NULL && !playerEntity->isDead())
      {
        if (!playerEntity->isSpecialStateActive(SpecialStateSlow))
        {
          playerEntity->setSpecialState(SpecialStateSlow, true, 0.1f, 0.33f, 0.0f);
          // TODO
          hurt(getHurtParams(2, ShotTypeStandard, 0, false, SourceTypeMelee, EnemyTypeNone, false));
        }
      }

      else if (!isFromPlayer && boltEntity != NULL && !boltEntity->getDying() && boltEntity->getAge() > 0.05f)
      {
        EnemyEntity::collideWithBolt(boltEntity);
      }
    }
    else // collision with other enemy ?
    {
      if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX)
      {
        if (this != entity)
        {
          EnemyEntity* enemyEntity = static_cast<EnemyEntity*>(entity);
          if (enemyEntity->canCollide()) collideWithEnemy(enemyEntity);
        }
      }
    }
  }
}
Пример #4
0
void ObstacleEntity::readCollidingEntity(CollidingSpriteEntity* entity)
{
  if (entity == this) return;
  if (!isDying && !isAgonising && collideWithEntity(entity))
  {
    if (entity->getType() == ENTITY_BOLT )
    {
      BoltEntity* boltEntity = dynamic_cast<BoltEntity*>(entity);

      if (!boltEntity->getDying() && boltEntity->getAge() > 0.05f)
      {
        EnemyEntity::collideWithBolt(boltEntity);
        correctFrame();
      }
    }
    else if (entity->getType() == ENTITY_ENEMY_BOLT )
    {
      EnemyBoltEntity* boltEntity = dynamic_cast<EnemyBoltEntity*>(entity);

      if (!boltEntity->getDying() && boltEntity->getAge() > 0.05f)
      {
        EnemyEntity::collideWithBolt(boltEntity);
        correctFrame();
      }
    }
    else if (entity->getType() >= ENTITY_ENEMY && entity->getType() <= ENTITY_ENEMY_MAX)
    {
      EnemyEntity* enemyEntity = dynamic_cast<EnemyEntity*>(entity);

      if (!enemyEntity->getDying() && enemyEntity->canCollide()&& enemyEntity->getMovingStyle() != movFlying)
      {
        hurt(getHurtParams(hp, ShotTypeStandard, 0, false, SourceTypeMelee, enemyEntity->getEnemyType(), false));
      }
    }
  }
}
Пример #5
0
void FairyEntity::tryToFire()
{
  if (x < TILE_WIDTH * 1.3) return;
  if (y < TILE_HEIGHT * 1.3) return;
  if (x > TILE_WIDTH * (MAP_WIDTH - 1) - TILE_WIDTH * 0.3) return;
  if (y > TILE_HEIGHT * (MAP_HEIGHT - 1) - TILE_HEIGHT * 0.3) return;

  if (fireDelay <= 0.0f)
  {
    if (fairyType == FamiliarFairyTarget)
    {
      Vector2D target = game().getNearestEnemy(x, y);
      if (target.x > -1.0f)
      {
        BoltEntity* bolt = new BoltEntity(x, y, FAIRY_BOLT_LIFE, shotType, shotLevel);
        bolt->setDamages(fairyDamages);
        bolt->setFlying(true);
        bolt->setVelocity(Vector2D(x, y).vectorTo(target, FAIRY_BOLT_VELOCITY));

        SoundManager::getInstance().playSound(SOUND_BLAST_STANDARD);
        fireDelay = game().getPlayer()->isEquiped(EQUIP_BELT_ADVANCED) ? fairyFireDelay * fireDelayAdvancedMult : fairyFireDelay;

        if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y))
        {
          if (target.x < x) facingDirection = 4;
          else facingDirection = 6;
        }
        else
        {
          if (target.y < y) facingDirection = 8;
          else facingDirection = 2;
        }
      }
      else
      {
        computeFacingDirection();
      }
    }
  }
  else
  {
    if (fairyType == FamiliarFairyTarget)
    {
      Vector2D target = game().getNearestEnemy(x, y);
      if (target.x > -1.0f)
      {
        if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y))
        {
          if (target.x < x) facingDirection = 4;
          else facingDirection = 6;
        }
        else
        {
          if (target.y < y) facingDirection = 8;
          else facingDirection = 2;
        }
      }
      else computeFacingDirection();
    }
  }
}
Пример #6
0
void FairyEntity::fire(int dir)
{
  if (x < TILE_WIDTH * 1.3) return;
  if (y < TILE_HEIGHT * 1.3) return;
  if (x > TILE_WIDTH * (MAP_WIDTH - 1) - TILE_WIDTH * 0.3) return;
  if (y > TILE_HEIGHT * (MAP_HEIGHT - 1) - TILE_HEIGHT * 0.3) return;

  if (fireDelay <= 0.0f)
  {
    switch (fairyType)
    {
    case FamiliarFairyIce:
      SoundManager::getInstance().playSound(SOUND_BLAST_ICE);
      break;
    case FamiliarFairyFire:
      SoundManager::getInstance().playSound(SOUND_BLAST_FIRE);
      break;
    default:
      SoundManager::getInstance().playSound(SOUND_BLAST_STANDARD);
      break;
    }

    fireDelay = game().getPlayer()->isEquiped(EQUIP_BELT_ADVANCED) ? fairyFireDelay * fireDelayAdvancedMult : fairyFireDelay;

    float velx = 0.0f;
    float vely = 0.0f;

    if (dir == 4) velx = - FAIRY_BOLT_VELOCITY;
    if (dir == 6) velx = + FAIRY_BOLT_VELOCITY;
    if (dir == 2) vely = + FAIRY_BOLT_VELOCITY;
    if (dir == 8) vely = - FAIRY_BOLT_VELOCITY;

    BoltEntity* bolt = new BoltEntity(x, y, FAIRY_BOLT_LIFE, shotType, shotLevel);
    bolt->setDamages(fairyDamages);
    bolt->setVelocity(Vector2D(velx, vely));
    bolt->setFlying(true);
    bolt->setFromPlayer(false);

    if (fairyType == FamiliarFairyTarget)
    {
      Vector2D target = game().getNearestEnemy(x, y);
      if (target.x > -1.0f)
      {
        bolt->setVelocity(Vector2D(x, y).vectorTo(target, FAIRY_BOLT_VELOCITY));

        if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y))
        {
          if (target.x < x) facingDirection = 4;
          else facingDirection = 6;
        }
        else
        {
          if (target.y < y) facingDirection = 8;
          else facingDirection = 2;
        }
      }
    }
  }
  else
  {
    if (fairyType == FamiliarFairyTarget)
    {
      Vector2D target = game().getNearestEnemy(x, y);
      if (target.x > -1.0f)
      {
        if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y))
        {
          if (target.x < x) facingDirection = 4;
          else facingDirection = 6;
        }
        else
        {
          if (target.y < y) facingDirection = 8;
          else facingDirection = 2;
        }
      }
      else computeFacingDirection();
    }
  }
}