Ejemplo n.º 1
0
void Ant::attack()
{
	Actor *pTarget = ActorHandler::getInstance()->getActor(mTarget);
	mCooldownCounter = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds) - mCooldownStartTime;
	//check if cooldownCounter is higher than weaponCooldown
	if(mCooldownCounter > 1.0f)
	{
		Tank *pTank = dynamic_cast<Tank*>(pTarget);
		Driver *pDriver = dynamic_cast<Driver*>(pTarget);
		mCooldownStartTime = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds);
		
		if(pTank != NULL)
		{
			safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
			pTank->reduceHp(mDamage);	
		}

		else if(pDriver != NULL)
		{
			safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
			pDriver->reduceHp(mDamage);
		}
	}
  //send event to have the enemy perform his attack animation
  //send event to collision checking for a hit
}
Ejemplo n.º 2
0
void Ant::attack()
{
  //if enemy is in range of tank
	Actor* pActor = ActorHandler::getInstance()->getActor(mpsPlayerInfo->getPlayerId());
	if(pActor != NULL && (pActor->getPosition() - mPosition).longerThan(Enemy::getRange(), false) == false && mId.isOwner())
	{
		mCooldownCounter = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds) - mCooldownStartTime;
		//check if cooldownCounter is higher than weaponCooldown
		if(mCooldownCounter > 1.0f)
		{
			Tank *pTank = dynamic_cast<Tank*>(pActor);
			Driver *pDriver = dynamic_cast<Driver*>(pActor);
			mCooldownStartTime = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds);
			
			if(pTank != NULL)
			{
				safeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
				pTank->reduceHp(15);	
			}

			else if(pDriver != NULL)
			{
				safeQueueEvent(EventDataPtr(myNew EvtData_From_EnemyMeleeAttack(this->getKey())));
				pDriver->reduceHp(15);
			}
		}

	}
  //send event to have the enemy perform his attack animation
  //send event to collision checking for a hit
}
void KamikazeAnt::attack()
{
	Actor* pActor = ActorHandler::getInstance()->getActor(mpsPlayerInfo->getPlayerId());
	if(pActor != NULL && (pActor->getPosition() - mPosition).longerThan(Enemy::getRange(), false) == false && mId.isOwner())
	{
		mCooldownCounter = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds) - mCooldownStartTime;
		//check if cooldownCounter is higher than weaponCooldown
		if(mCooldownCounter > 1.0f)
		{
			Tank *pTank = dynamic_cast<Tank*>(pActor);
			Driver *pDriver = dynamic_cast<Driver*>(pActor);
			mCooldownStartTime = mpGlobalTimer->getTime(utilities::Timer::ReturnType_Seconds);

			if(pTank != NULL)
			{
				safeQueueEvent(EventDataPtr(myNew EvtData_From_KamikazeAntExplode(this->getKey())));
				pTank->reduceHp(50);
				this->reduceHp(200);
			}

			else if(pDriver != NULL)
			{
				safeQueueEvent(EventDataPtr(myNew EvtData_From_KamikazeAntExplode(this->getKey())));
				pDriver->reduceHp(50);
				this->reduceHp(200);
			}
		}

	}
}
Ejemplo n.º 4
0
void Munitions::handleEventId(EventData const &eventMessage)
{
	if(EvtData_From_ActorCollisionObject::msEventType == eventMessage.getEventType())
	{
		const EvtData_From_ActorCollisionObject& evtData = static_cast<const EvtData_From_ActorCollisionObject&>(eventMessage);
		Munitions *pMunition = dynamic_cast<Munitions*>(ActorHandler::getInstance()->getActor(evtData.mFirstActorId));
		Actor *pSecondActor = ActorHandler::getInstance()->getActor(evtData.mSecondActorId);
		Actor::ActorTypes secondActorType = pSecondActor->getActorType();
		Actor::ActorTypes munitionOwnerType = pMunition->getOwnerType();

		//if a enemy collides with a munition
		if(secondActorType == Actor::ActorType_Enemy)
		{
			Enemy* pEnemy = dynamic_cast<Enemy*>(pSecondActor);			
			if((munitionOwnerType == Actor::ActorType_Tank || munitionOwnerType == Actor::ActorType_Driver) && pEnemy->getHealthPoints() > 0)
			{
				if(pEnemy->getKey().isOwner())
				{
					pEnemy->reduceHp(Weapon::calculateDamage(pMunition->getEfficiency(),pEnemy->getEnemySize(),pMunition->getDamage()), eventMessage.getNetworkId(), pMunition->getOwner());
				}
				else
				{
					safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_To_ActorReduceHp(pEnemy->getKey(), Weapon::calculateDamage(pMunition->getEfficiency(),pEnemy->getEnemySize(),pMunition->getDamage()), pMunition->getOwner())));
				}
			}
		}

		//if a tank collides with a munition
		else if(secondActorType == Actor::ActorType_Tank)
		{
			Tank*  pTank = dynamic_cast<Tank*>(pSecondActor);
			if(munitionOwnerType == Actor::ActorType_Enemy)
			{
				if(pTank->getKey().isOwner())
				{
					pTank->reduceHp(pMunition->getDamage());
				}
				else
				{
					safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_To_ActorReduceHp(pTank->getKey(), pMunition->getDamage(), pMunition->getOwner())));
				}
			}
		}

		//if a driver collides with a munition
		else if(secondActorType == Actor::ActorType_Driver)
		{
			Driver*  pDriver = dynamic_cast<Driver*>(pSecondActor);
			if(munitionOwnerType == Actor::ActorType_Enemy)
			{
				if(pDriver->getKey().isOwner())
				{
					pDriver->reduceHp(pMunition->getDamage());
				}
				else
				{
					safeThreadSafeQueueEvent(EventDataPtr(myNew EvtData_To_ActorReduceHp(pDriver->getKey(), pMunition->getDamage(), pMunition->getOwner())));
				}
			}
		}
	}
}