游戏操作杆代码
enum Direction {
CENTER = 0,
UP,
DOWN,
LEFT,
RIGHT
};
Direction JudgeUpDownLeftRight(CPoint pt, CPoint center, int nCenterR)
{
//不包含边界计算
int absToY = abs(pt.x - center.x);
int absToX = abs(pt.y - center.y);
if (( absToX < nCenterR) &&
( absToY < nCenterR))
{
return CENTER;
}
if (pt.x >= center.x && pt.y < center.y)
{
if (absToX < absToY)
{
return RIGHT;
}
else
{
return UP;
}
}
else if (pt.x < center.x && pt.y < center.y)
{
if (absToX < absToY)
{
return LEFT;
}
else
{
return UP;
}
}
else if (pt.x < center.x && pt.y >= center.y)
{
if (absToX < absToY)
{
return LEFT;
}
else
{
return DOWN;
}
}
else /*if (pt.x >= center.x && pt.y >= center.y)*/
{
if (absToX < absToY)
{
return RIGHT;
}
else
{
return DOWN;
}
}
}