Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ do while loop
    primarykey
    data
    text
    <p>I have a vector holding 10 items (all of the same class for simplicity call it 'a'). What I want to do is to check that 'A' isn't either a) hiding the walls or b) hiding another 'A'. I have a collisions function that does this. </p> <p>The idea is simply to have this looping class go though and move 'A' to the next position, if that potion is causing a collision then it needs to give itself a new random position on the screen. Because the screen is small, there is a good chance that the element will be put onto of another one (or on top of the wall etc). The logic of the code works well in my head - but debugging the code the object just gets stuck in the loop, and stay in the same position. 'A' is supposed to move about the screen, but it stays still!</p> <p>When I comment out the Do while loop, and move the 'MoveObject()' Function up the code works perfectly the 'A's are moving about the screen. It is just when I try and add the extra functionality to it is when it doesn't work. </p> <pre><code> void Board::Loop(void){ //Display the postion of that Element. for (unsigned int i = 0; i &lt;= 10; ++i){ do { if (checkCollisions(i)==true){ moveObject(i); } else{ objects[i]-&gt;ResetPostion(); } } while (checkCollisions(i) == false); objects[i]-&gt;SetPosition(objects[i]-&gt;getXDir(),objects[i]-&gt;getYDir()); } } </code></pre> <p>The class below is the collision detection. This I will expand later. </p> <pre><code> bool Board::checkCollisions(int index){ char boundry = map[objects[index]-&gt;getXDir()][objects[index]-&gt;getYDir()]; //There has been no collisions - therefore don't change anything if(boundry == SYMBOL_EMPTY){ return false; } else{ return true; } } </code></pre> <p>Any help would be much appreciated. I will buy you a virtual beer :-)</p> <p>Thanks</p> <p>Edit:</p> <p>ResetPostion -> this will give the element A a random position on the screen moveObject -> this will look at the direction of the object and adjust the x and Y cord's appropriately. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload