本文整理汇总了C++中CEntity::emitMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ CEntity::emitMessage方法的具体用法?C++ CEntity::emitMessage怎么用?C++ CEntity::emitMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CEntity
的用法示例。
在下文中一共展示了CEntity::emitMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process
void CLifeModifier::process(CMessage *message) {
CMessageUInt* rxMsg = static_cast<CMessageUInt*>(message);
CEntity* entity = _entity->getMap()->getEntityByID( rxMsg->getUInt() );
CMessageUInt *txMsg = new CMessageUInt();
//LifeModifier manda un mensaje al componente LIFE.cpp
// mensaje TIPO LIFE_MODIFIER. Action = DAMAGE, HEAL
txMsg->setType(Message::LIFE_MODIFIER);
//PT. se carga en el entero el modificador de vida (negativo o positivo)
//txMsg->setUInt( abs(_LIFE_MODIFIER) );
txMsg->setUInt(_LIFE_MODIFIER );
if (_LIFE_MODIFIER < 0)
txMsg->setAction(Message::DAMAGE);
else if(_LIFE_MODIFIER > 0)
txMsg->setAction(Message::HEAL);
//PT. It just worth sending message when it hurts or heals, when is 0 doesnt worthy
if(_LIFE_MODIFIER != 0 && _entity!=NULL)
entity->emitMessage(txMsg, this);
} // process
示例2: process
void CShieldSpecialController::process(const std::shared_ptr<Logic::IMessage> &message)
{
// Solo realizará el cambio de dirección si el anterior cambio que hizo no fue el
// mismo que va a realizar (de modo que no esté entrando constántemente al mismo y "tiemble)
if (message->getType() == "FALLING" && _lastCollision != "DOWN")
{
bool isFalling = dynamic_cast<FALLING*>(message.get())->getBool();
if (!isFalling)
{
_dirPong.y *= -1;
_lastCollision = "DOWN";
_numHitsPong++;
///Lanzamos sonido de colision
std::shared_ptr<PLAY_SOUND> sound (new PLAY_SOUND());
sound->setSound(std::string("/Armas/Escudo/ReboteEscudo"));
_entity->emitMessage(sound, this);
}
}
else if (message->getType() == "UP_COLLISION" && _lastCollision != "UP")
{
_dirPong.y *= -1;
_lastCollision = "UP";
_numHitsPong++;
//BaseSubsystems::Log::Debug("UP");
///Lanzamos sonido de colision
std::shared_ptr<PLAY_SOUND> sound (new PLAY_SOUND());
sound->setSound(std::string("/Armas/Escudo/ReboteEscudo"));
_entity->emitMessage(sound, this);
}
else if (message->getType() == "SIDE_COLLISION")
{
std::string thisCollision;
int normal = dynamic_cast<SIDE_COLLISION*>(message.get())->getNormalCollision();
//BaseSubsystems::Log::Debug("SIDE : " + std::to_string(normal));
if (normal != 0)
{
if (normal == 1)
thisCollision = "RIGHT";
else if (normal == -1)
thisCollision = "LEFT";
if (thisCollision != _lastCollision)
{
_lastCollision = thisCollision;
_dirPong.x *= -1;
_numHitsPong++;
///Lanzamos sonido de colision
std::shared_ptr<PLAY_SOUND> sound (new PLAY_SOUND());
sound->setSound(std::string("/Armas/Escudo/ReboteEscudo"));
_entity->emitMessage(sound, this);
}
}
}
if(message->getType().compare("TOUCHED") == 0)
{
CEntity* otherEntity = dynamic_cast<TOUCHED*>(message.get())->getEntidad();
if( otherEntity != NULL)
{
//Si golpeo a un enemigo genero chispa roja, si golpeo la puerta la normal
if(otherEntity->getTag() == "enemy")
{
CEntityFactory::getSingletonPtr()->createEntityByType("ChispaDanhoEnemy",_entity->getPosition(), _entity->getMap());
std::shared_ptr<DAMAGED>m(new DAMAGED());
m->setFloat(_damage);
m->setString(_entity->getType());
otherEntity->emitMessage(m, this);
std::shared_ptr<PUSH> push (new PUSH());
push->setDirection(_dirPong);
push->setSpeed(0.6f);
otherEntity->emitMessage(push, this);
///Lanzamos sonido de colision
std::shared_ptr<PLAY_SOUND> sound (new PLAY_SOUND());
sound->setSound(std::string("/Armas/Escudo/ReboteEscudo"));
_entity->emitMessage(sound, this);
sendSET_MATERIAL(_materialSangre);
_timeAcum = 0;
_countToClean = true;
}
else if( otherEntity->getTag() == "objetoRompible")
{
CEntityFactory::getSingletonPtr()->createEntityByType("Chispa",_entity->getPosition(), _entity->getMap());
std::shared_ptr<DAMAGED>m(new DAMAGED());
m->setFloat(_damage);
m->setString(_entity->getType());
otherEntity->emitMessage(m, this);
///Lanzamos sonido de colision
std::shared_ptr<PLAY_SOUND> sound (new PLAY_SOUND());
sound->setSound(std::string("/Armas/Escudo/ReboteEscudo"));
//.........这里部分代码省略.........