游戏操作杆代码

游戏操作杆代码

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;
        }
    }
}

 

posted @ 2020-04-22 10:04  余生以学  阅读(193)  评论(0编辑  收藏  举报