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; } } } } } }
void Bomb::DestructibleBox::EventTreatment() { if (this->_events.size()) { Event::DamageEvent *dam = static_cast<Event::DamageEvent *>(this->_events.front()); this->_events.pop_front(); if (dam && dam->id == this->GetId()) { LifeComponent *life = static_cast<LifeComponent *>(this->GetComponent(Life_c)); if (life) { life->Damage(dam->damage); if (life->GetLife() <= 0) G_EvDispatcher->SendEvent(new Event::ScoreEvent(Event::KillTargetScoring, dam->sender, this->GetId()), Event::COMMON); } } delete dam; } }