Ejemplo n.º 1
0
void BlitzleApp::aimNextFrame() const
{
	cv::Mat frame;
	desktop->acquireNextFrame(frame);

	std::vector<cv::Point> players;
	detector->processFrame(frame, players);

	cv::Point crosshair = cv::Point(int(frame.cols * 0.5f), int(frame.rows * 0.5f));
	cv::Point target;
	bool targetFound = getClosestTarget(players, crosshair, target);

#ifndef _DEBUG
	if (targetFound)
	{
		cv::Point delta = cv::Point(target.x - crosshair.x, target.y - crosshair.y);
		if (delta.x != 0 && delta.y != 0)
		{
			interceptor->setTargetDelta(int(delta.x * opts.sensivity), int(delta.y * opts.sensivity));
		}
	}
	else
	{
		interceptor->unsetTarget();
	}
#endif
}
Ejemplo n.º 2
0
void Towers::checkTarget() {
	//    if(_target){
	double curDistance = ccpDistance(getPosition(), _target->getPosition());
	if (_target->getHp()<= 0 || curDistance>_range){
		_target =getClosestTarget();
	}
	//    }

}
Ejemplo n.º 3
0
void Towers::towerLogic(float dt) {
	//    if(_target==NULL){
	_target = getClosestTarget();
	//    }


	if (_target != NULL) {

		//rotate the tower to face the nearest creep
		CCPoint shootVector = ccpSub(_target->getPosition(), getPosition());
		float shootAngle = ccpToAngle(shootVector);
		float cocosAngle = CC_RADIANS_TO_DEGREES(-1 * shootAngle);

		float rotateSpeed = 0.5 / M_PI; // 1/2 second to roate 180 degrees
		float rotateDuration = fabs(shootAngle * rotateSpeed);

		runAction(CCSequence::create(CCRotateTo::create(rotateDuration,cocosAngle),
			CCCallFunc::create(this,callfunc_selector(Towers::finishFiring)),NULL));
	}
}
Ejemplo n.º 4
0
bool MonsterFSM::States( StateMachineEvent event, Message_s * msg, int state )
{
	ASSERT(m_Owner!=0, "Owner was NULL");

// Do the state machine:
BeginStateMachine

	///////////////////////////////////////////////////////////////
	State( STATE_Rnd )
		OnEnter
			m_Owner->CancelOrders();

		OnMsg( MSG_ATTACKED )
			// Attacker becomes our target, retaliate
			if(msg->m_Sender != targetCreatureHANDLE)
			{
				targetCreatureHANDLE = msg->m_Sender;
				SetState(STATE_Attack);
			}

		OnUpdate
			targetCreatureHANDLE = getClosestTarget();

			/*
			If a player is close enough to get our attention, then attack.
			Otherwise, wander randomly
			*/
			if(targetCreatureHANDLE != INVALID_ID)
			{
				SetState(STATE_Pause_Before_Attack);
			}
			else if(m_Owner->anyCollisions() || !m_Owner->HasOrders())
			{
				// Go someplace random
				m_Owner->CancelOrders();
				vec3 waypoint = getRandomWalk();
				float speed = FRAND_RANGE(0.5f, 0.7f);
				m_Owner->QueueCommand(CommandMoveToLocation(waypoint, speed, FLT_EPSILON, 2000.f));
			}

	///////////////////////////////////////////////////////////////
	State( STATE_Pause_Before_Attack )
		OnEnter
			// pause for a moment before reacting
			m_Owner->CancelOrders();
			m_Owner->QueueCommand(CommandFreeze(FRAND_RANGE(200.0f, 400.0f), targetCreatureHANDLE));

		OnUpdate
			if(!m_Owner->HasOrders())
			{
				SetState(STATE_Attack);
			}

	///////////////////////////////////////////////////////////////
	State( STATE_Attack )
		OnEnter
			m_Owner->CancelOrders();
			g_SoundSystem.play(m_Owner->getAttnSfx());

		OnMsg( MSG_ATTACKED )
			// Attacker becomes our new target, retaliate
			if(msg->m_Sender != targetCreatureHANDLE)
			{
				targetCreatureHANDLE = msg->m_Sender;
				SetState(STATE_Attack);
			}

		OnUpdate
			/*
			If we don't have a target, resume wandering.
			Else If target is out of range, resume wandering
			Else If we are low on health, flee.
			Else If we don't have anything to do, keep attacking.
			*/
			if(!haveTarget())
			{
				SetState(STATE_Rnd);
			}
			else if(distanceToTarget() > thresholdLoseInterest)
			{
				SetState(STATE_Rnd);
			}
			else if(m_Owner->getHealthPercentage() < fleeThresholdForHealth)
			{
				SetState(STATE_Flee);
			}
			else if(!m_Owner->HasOrders())
			{
				orderTheAttack();
			}

	///////////////////////////////////////////////////////////////
	State( STATE_Flee )
		OnEnter
			m_Owner->CancelOrders();
			g_SoundSystem.play(m_Owner->getAttnSfx());

		OnMsg( MSG_ATTACKED )
			// Attacker becomes our new target, flee
			if(msg->m_Sender != targetCreatureHANDLE)
			{
				targetCreatureHANDLE = msg->m_Sender;
				SetState(STATE_Flee);
			}

		OnUpdate
			/*
			If we don't have a target, resume wandering.
			Else If target is out of range, resume wandering
			Else If we are not low on health anymore, attack again.
			Else If we don't have anything to do, keep fleeing.
			*/
			if(!haveTarget())
			{
				SetState(STATE_Rnd);
			}
			else if(distanceToTarget() > thresholdLoseInterest)
			{
				SetState(STATE_Rnd);
			}
			else if(m_Owner->getHealthPercentage() >= fleeThresholdForHealth)
			{
				SetState(STATE_Attack);
			}
			else if(!m_Owner->HasOrders())
			{
				m_Owner->QueueCommand(CommandFlee(targetCreatureHANDLE, FRAND_RANGE(0.9f, 1.0f), thresholdLoseInterest, 5000.0f));
			}

	///////////////////////////////////////////////////////////////
EndStateMachine
}