所以我用 SFML 库用 C++ 制作游戏,我面临这个问题,我的蜈蚣段每次碰到侧面边界时都会断开连接

问题描述 投票:0回答:1

蜈蚣每次撞到边界或网格的左侧或右侧时都会断开一段连接。有人可以帮助我吗?如果需要,我可以提供更多详细信息。

void movecentipede(float centipede[][4],int segments,int segmentsize) {
    bool movingright = true;
    float distanceX = 0.1f;
    float distanceY = 0.2f;
    for (int i=0;i<segments;i++) {
        
        //RIGHT
        if (movingright) {  
            //cout<<"hello"<<endl;
            centipede[i][x] += distanceX;
        }
        //LEFT
        else {
            centipede[i][x] -= distanceX;

        }
        //HEAD REACHES BOUNDARY TO RIGHT
        if (centipede[i][x] > resolutionX-segmentsize) {
            centipede[i][x] = resolutionX-segmentsize;
            centipede[i][y] += distanceY;
            movingright = false;
            //cout<<'\n'<<i<<" ";
        }
        
        //HEAD REACHES BOUNDARY TO LEFT
        else if (centipede[i][x] < 0) {
            centipede[i][x] = 0;
            centipede[i][y] += distanceY;
            movingright = true;
        } 
    }
}

所以每次它碰到右边界或左边界时,它就会断开蜈蚣的一段。我尝试调试它,但我不能。

c++ sfml
1个回答
0
投票

将您的完整代码发送给我查看。

© www.soinside.com 2019 - 2024. All rights reserved.