At the moment though from what I can tell, this doesn't work... So in my main function I have this code to test for a collision:
1 2 3 4 5
Collision(collision);//calls collision function to check collisions
if(collision == true){
m_Screen->Print("COLLISION", 2, 2, 0xffffff);//prints collision in top left corner
}
I can't it to detect collisions, at least not print the line...
Anyone know what I'm doing wrong? Any help is much appreciated.
Ah I miss-worded that ehm, the program runs but the Collision() function doesn't detect collisions :/
Can you see anything wrong with the function I wrote?
Chaining together a million && and || conditions is ugly. Look at how confusing that is. As a general rule, if you're doing more than one &&/|| in a single conditional, you're probably making it too complicated (there are exceptions to that rule, of course).
I say Simplify it!
1 2 3 4 5 6 7 8 9 10
bool Collision()
{
if(tankX > (turrentX + turrentW)) returnfalse; // tank to the right of the turrent
if(turrentX > ( tankX + tankW)) returnfalse; // tank to the left of the turrent
if(tankY > (turrentY + turrentH)) returnfalse; // tank below
if(turrentY > ( tankY + tankH)) returnfalse; // tank above
// if none of those were true, then the tank must be on top of the turret
returntrue;
}