Ane we usually guard these with #ifdef DEBUG ... #endif /* DEBUG */ blocks so that you can turn the printf statements off when you are ready for production. Example:
void checkcollision()
{
float x1 = tanks[0].x;
float y1 = tanks[0].y;
float x2 = tanks[1].x;
float y2 = tanks[1].y;
float dist = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
float dr = tanks[0].rad+tanks[1].rad;
#ifdef DEBUG
printf("dist: %f, radius+radius: %f\n",dist, dr);
if(1 < 2)
{
puts("yes");
}
else
{
puts("wtf");
}
#endif /* DEBUG */
if(dist < dr) ;
{
printf("checkcollision read true\n");
printf("dist: %f, radius+radius: %f\n",dist,dr);
goback(0); goback(1);
}
}
So, when you have a valid value, yet you don't get the output from inside the if (dist<dr)
clause, then you know you need to look there. In any case, this sort of bug is common to beginners. Another one is to have single line contents of a conditional and not use curly-braces, so when you add code later that should be inside the conditional, it doesnt work correctly. Example:
if(dist < dr) /* Note - no semicolon now */
goback(0); goback(1);
This will be another bug since the second goback(1) will execute whether or not dist < dr
. Rule: ALWAYS brace ALL conditional blocks of code, whether they are one liners or not. First, it is easier to read. Second, adding more code within the conditional will be less likely to result in inadvertant bugs.
One final thing. Do NOT, if at all possible, execute two separate statements …