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);
                }
            }
        }
    }
}
Beispiel #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);
        }
      }
    }
  }
}
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);
}
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);
}
Beispiel #5
0
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();
}
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);
}
void JoustTileMapEntity::generateFallingTiles()
{
    for (int i = 0; i < gameMap->getWidth(); i++)
        for (int j = 0; j < gameMap->getHeight(); j++)
        {
            int tile = ((JoustGameMap*)gameMap)->getDifferenceTile(i, j);
            if (tile != 0)
            {
                SpriteEntity* fallingBlock  = new SpriteEntity( image,
                                                                (float)(OFFSET_X + tileWidth * i + tileWidth / 2),
                                                                (float)(OFFSET_Y + tileHeight * j + tileHeight / 2),
                                                                tileWidth,
                                                                tileHeight,
                                                                tilesProLine);
                fallingBlock->setFrame(tile);
                fallingBlock->setLifetime(1.0f);
                fallingBlock->setFading(true);
                fallingBlock->setWeight(30.0f);
                fallingBlock->setSpin(-50.0f + 100.0f * (float)rand() / (float)RAND_MAX);
            }
        }

    ((JoustGameMap*)gameMap)->initDifferenceMap();
}