Beispiel #1
0
void CPlayer::Update(float dt)
{
	CIwFVec2 path = MovePos - ControlledObject->getPos();
	if(path.GetLengthSquared() > (cachesSquaredSize / 2) )
	{
		ControlledObject->setDir(path);
		ControlledObject->setSpeed(50);
	}
	else
	{
		ControlledObject->setSpeed(0);
	}
}
Beispiel #2
0
void Unit::path(std::list<Unit*>::iterator itr) {
	
	CIwFVec2 force = CIwFVec2::g_Zero;
	
	std::list<Unit*>* units = game->getUnits();
	float theta = getTheta();
	
	CIwFVec2 dirToward = CIwFVec2::g_Zero;
	Unit* curUnit;
	
	//brute force - need to take advantage of theta sorting
	for (itr = units->begin() ; itr != units->end(); ++itr) {
		curUnit = *(itr);
		
		if ((*itr) != this && THETA_DIFF(curUnit->getTheta(), theta) < PATH_THETA_RANGE) {
			dirToward = position - curUnit->getPosition();
			float dist = dirToward.GetLengthSquared();
			force += dirToward.GetNormalised() * (curUnit->getSize()*REPEL_FACTOR / pow(dist, 1.875));
            // We can tweak bottom factor later, this seems to work fine:           ^
		}
	}
		
	//attractive force for opponent leader
	Player* opponent = game->getLocalPlayer() != owner ? owner : game->getOpponentPlayer();
	dirToward = ((Unit*)(opponent->getLeader()))->getPosition() - position;
	float dist = dirToward.GetLength();

    if(dist > 0)
        force += dirToward.GetNormalised() * (LEADER_ATTRACTION / dist);	
	
	//"spring" force to motivate circular pathing
	float centerR = (game->getWorldRadius().y + game->getWorldRadius().x)/2.0;
	float rDiff = centerR - r;
	force += position * ((rDiff < 0 ? -1 : 1) * WALL_REPEL * SQ(rDiff)); // Ternary is experimentally faster
			
	velocity = speed*force.GetNormalised();
	setPosition(position + velocity);
}