示例#1
0
文件: CMinesweeper.cpp 项目: Supy/ml
SVector2D CMinesweeper::GetClosestSuperMine(vector<CCollisionObject> &objects)
{
	double			closest_so_far = 999999999;

	SVector2D		vClosestObject(0, 0);

	//cycle through mines to find closest
	for (int i=0; i<objects.size(); i++)
	{
		if(objects[i].getType() == CCollisionObject::SuperMine){
			double len_to_object = Vec2DLengthSquared(objects[i].getPosition() - m_vPosition);

			if (len_to_object < closest_so_far)
			{
				closest_so_far	= len_to_object;
			
				vClosestObject	= objects[i].getPosition() - m_vPosition;

				m_iClosestSuperMine = i;
			}
		}
	}

	return vClosestObject;
}
示例#2
0
//----------------------GetClosestObject()---------------------------------
//
//	returns the vector from the sweeper to the closest mine
//
//-----------------------------------------------------------------------
SVector2D CMinesweeper::GetClosestMine(vector<SVector2D> &mines)
{
    double			closest_so_far = 99999;

    SVector2D		vClosestObject(0, 0);

    //cycle through mines to find closest
    for (int i=0; i<mines.size(); i++)
    {
        double len_to_object = Vec2DLength(mines[i] - m_vPosition);

        if (len_to_object < closest_so_far)
        {
            closest_so_far	= len_to_object;

            vClosestObject	= m_vPosition - mines[i];

            m_iClosestMine = i;
        }
    }

    return vClosestObject;
}