So i wrote a collision detection function for a game im creating and it works as i want it to but now i'm trying to make it more general so it accepts any 2 objects and checks if there is a collision between them.
Now i understand that i'm passing a copy of these objects rather than the objects themselves to the function but i don't think that should affect it as no action is performed in the function.
I think my question can be best phrased like this:
Why does the first example work and the second not?
Ok i was aware of this but i dont think it should make much difference as b is reset on each iterate and only one of the 4 if statements can ever be triggered at the same time. But i guess i'll look into this again a bit later.
How would you suggest i go about the whole passing objects to a function to check, do i just need to rework my function or is there some clever trick im missing??
Is "walls.wall.w" an integer that could be compared to "entity.getxpos()"? In the first example you are explicitly listing an offset of 64, in the second one you seem to be trying to use the width of the image as your offset. Assuming your copy constructor is ok this could be your issue.
Have you considered refactoring your conditionals into a function and passing the arguments by reference?
If only one of the cases can be triggered at a time, should you just "continue" the loop after a condition is satisfied? Or maybe use "else if" to indicate that only one option is possible?