Exemplo n.º 1
0
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
	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"));
					_entity->emitMessage(sound, this);
				}
				
			}
			//Si golpeo un tile genera chispa normal
			else
			{
				CEntityFactory::getSingletonPtr()->createEntityByType("Chispa",_entity->getPosition(),_entity->getMap());
			}
		}

	} // process