Beispiel #1
0
void			Bomb::NormalBomb::Destroy()
{
  if (this->HasComponent(Explode_c) && !this->_isDestroy)
    {
      AudioComponent	*audio = static_cast<AudioComponent *>(this->GetComponent(Audio_c));
      if (audio)
	audio->PlaySound(_sound);
      this->_isDestroy = true;
      ExplodeComponent  *explode
	= static_cast<ExplodeComponent *>(this->GetComponent(Explode_c));
      if (explode)
	{
	  explode->Update();
	  IEntity		*player
	    = static_cast<Player *>(G_ObjectsContainer->GetObjById(explode->GetOwner(), Player_o));
	  if (player)
	    {
	      if (player && player->HasComponent(Bomb_c))
		{
		  G_EvDispatcher->SendEvent(new Event::GraphicEvent(this, Graphic::MESHDEL),
					    Event::COMMON);
		  BombComponent	*bomb
		    = static_cast<BombComponent *>(player->GetComponent(Bomb_c));
		  if (bomb)
		    bomb->AddBomb(Normal);
		}
	    }
	}
      G_EvDispatcher->SendEvent(new Event::DestroyEvent(this->GetId()), Event::COMMON);
    }
}
Beispiel #2
0
void	Bomb::DropBonusComponent::Update()
{
  PositionComponent *pos
    = static_cast<PositionComponent *>(this->GetParent()->GetComponent(Position_c));
  LifeComponent *life
    = static_cast<LifeComponent *>(this->GetParent()->GetComponent(Life_c));
  enum GameObjectTag	bonusTab[3];

  bonusTab[0] = BonusSpeed_o;
  bonusTab[1] = BonusAddBomb_o;
  bonusTab[2] = BonusSizeBomb_o;
  ListObj	*list_world = G_ObjectsContainer->GetObjByTag(World_o);
  if (list_world && life && life->GetLife() <= 0 && !this->_dropped)
    {
      IEntity	*world = list_world->front();
      if (world)
	{
	  MapComponent	*map = static_cast<MapComponent *>(world->GetComponent(Map_c));
	  if (pos && map)
	    {
	      double posX = pos->GetPosition(PositionComponent::X);
	      double posY = pos->GetPosition(PositionComponent::Y);

	      if (rand() % 10 < 4)
		{
		  IEntity	*bonus = G_EntityFactory->Create(bonusTab[rand() % 3]);

		  if (bonus)
		    {
		      pos = static_cast<PositionComponent *>(bonus->GetComponent(Position_c));

		      G_ObjectsContainer->AddObj(bonus);
		      G_EvDispatcher->SendEvent(new Event::GraphicEvent(bonus, Graphic::MESHADD),
		      				Event::COMMON);
		      pos->SetPosition(posX, posY);
		      map->AddEntity(bonus, posX, posY);
		      bonus->Start();
		      this->_dropped = true;
		    }
		}
	    }
	}
    }
}
int main(int argc, char **argv)
{
	CEntityPool EntityPool(-1); // Create an entity pool for 900 entities (default limit for GoldSrc)
	
	IEntity *pEntity = EntityPool.AllocEntity();
	
	pEntity->SetName("Test1");
	
	ISoundComponent *pSoundComponent = pEntity->GetComponent("SoundComponent");
	pSoundComponent->PlaySound("test_sound.wav");
	
	pEntity = EntityPool.AllocEntity("Test2");
	
	pEntity = EntityPool.GetByName("Test1"); // [!] Warning: potential name collisions
	pEntity->Free();
	
	// EntityPool gets destroyed here and free all allocated entities
	return 0;
};