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);
}
Beispiel #2
0
void LevelEditor::createGhostEntity(Vec2f worldPos)
{
    if(newEntityName != "")
    {
        std::shared_ptr<sf::Texture> texture = std::make_shared<sf::Texture>();
        texture->loadFromFile(newEntityName);

        SpriteEntity* newEntity = new SpriteEntity();
        newEntity->create(texture);
        newEntity->setOrigin(Vec2f(0.5, 0.5));

        ghostEntity = newEntity;
        ghostEntity->setPosition(worldPos);

        std::cout << texture.use_count() << std::endl;
    }
}
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);
                }
            }
        }
    }
}
void SwarmGame::transformToZombie(EntitySprite& entity)
{
   EntityType toType;
   if (transformToType(entity.m_entity->type(), toType))
   {
      MobileEntity* zombie = static_cast<MobileEntity*>(EntityFactory::instance().createEntity(toType));
      if ( NULL != zombie  )
      {
         m_ZombieSwarm.addEntity(zombie);
         CCTexture2D* entityTexture = NULL;
         CCTextureCache* textureCache = CCTextureCache::sharedTextureCache();
         entityTexture = textureCache->textureForKey(xmlDataManager::instance().getEntitySprite (toType));
         int mapHeight = m_map.height() * c_blockSize;

         //create new sprite
         SpriteEntity* sprite = SpriteEntity::spriteWithEntity(zombie);
         sprite->setAnchorPoint(entity.m_sprite->getAnchorPoint());
         sprite->setScaleX(entity.m_sprite->getScaleX());
         sprite->setScaleY(entity.m_sprite->getScaleY());
         sprite->setPosition(entity.m_sprite->getPosition());

         m_mapLayer->removeChild(entity.m_sprite, true);
         entity.m_sprite = sprite; 
         entity.m_sprite->setMaxHealth( zombie->hitPoints() );
         entity.m_sprite->setIsVisible(true);
         m_mapLayer->addChild(entity.m_sprite);

         //TODO: add more properties
         m_map.removeEntity(entity.m_entity);
         m_map.placeEntity(zombie, entity.m_entity->x(), entity.m_entity->y());

         m_ZombieSwarm.removeTarget(entity.m_entity);
         m_HumanSwarm.removeEntity(entity.m_entity, true);
         //m_map->removeEntity(entity.m_entity);
         m_HumanSwarm.addTarget (zombie);

         entity.m_entity = zombie;         
      }
   }
}
Beispiel #5
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 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);
}
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 SlimePetEntity::fall()
{
    SpriteEntity* spriteEntity
        = new SpriteEntity(ImageManager::getInstance().getImage(IMAGE_SLIME),
                           x,
                           y + 6,
                           64, 64, 4);
    spriteEntity->setAge(0.0f);
    spriteEntity->setLifetime(3.0f);
    spriteEntity->setShrinking(true);
    spriteEntity->setFading(true);
    spriteEntity->setFrame(16);

    isDying = true;

    SlimePetEntity* newSlime = new SlimePetEntity();
    newSlime->setAge(-4.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();
}
Beispiel #10
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 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);
  }
}