I have a vector containing 10 elements (all the same classes are called "a" for simplicity). What I want to do is to verify that "A" is not a) a concealment of walls, or b) a concealment of another "A". I have a collision function that does this.
The idea is to simply start this cycle, and move "A" to the next position, if this potion causes a collision, then it needs to be given a new random position on the screen. Since the screen is small, there is a good chance that the element will be placed in another (or over the wall, etc.). The logic of the code works well in my head - but debugging the code, which the object just gets stuck in the loop, and remains in the same position. "A" should move around the screen, but it remains stationary!
When I comment on the Do while loop and move the MoveObject () function, the code works fine, "A moves around the screen. It is simple when I try to add additional functions when it does not work.
void Board::Loop(void){
for (unsigned int i = 0; i <= 10; ++i){
do {
if (checkCollisions(i)==true){
moveObject(i);
}
else{
objects[i]->ResetPostion();
}
}
while (checkCollisions(i) == false);
objects[i]->SetPosition(objects[i]->getXDir(),objects[i]->getYDir());
}
}
The next class is collision detection. This I will tell later.
bool Board::checkCollisions(int index){
char boundry = map[objects[index]->getXDir()][objects[index]->getYDir()];
if(boundry == SYMBOL_EMPTY){
return false;
}
else{
return true;
}
}
Any help would be greatly appreciated. I will buy you a virtual beer :-)
thank
Edit:
ResetPostion → this will give element A a random position on the screen moveObject → it will look at the direction of the object and correctly adjust the cords x and Y.
source
share