蜈蚣每次撞到边界或网格的左侧或右侧时都会断开一段连接。有人可以帮助我吗?如果需要,我可以提供更多详细信息。
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;
}
}
}
所以每次它碰到右边界或左边界时,它就会断开蜈蚣的一段。我尝试调试它,但我不能。
将您的完整代码发送给我查看。