Why does the Collision Boolean feel, awkward?

Looking at the Boolean Declaration for the Collision with Axe we have
bool collision_with_axe = (b_axe_y >= u_circle_y) && (u_axe_y <= b_circle_y) && (r_axe_x >= l_circle_x) && (l_axe_x <= r_circle_x);

So my understanding is The Boolean is set to all of those values, at the same time as “False”

And the Collision Detection code is:
collision_with_axe = (b_axe_y >= u_circle_y) && (u_axe_y <= b_circle_y) && (r_axe_x >= l_circle_x) && (l_axe_x <= r_circle_x);

And the Collision with Axe is set, to several Values at once. But my question is, Why do this? As far as I can tell, the Boolean is set to four conditional checks and uses And to “merge” them. Wouldn’t it be better to use an If Then instead?

Six of one thing, half dozen of another. Its personal opinion which would be “better”. I suppose the thinking is that this way puts all the collision conditions up front so it reads more as cause :arrow_forward: effect rather than scattering the causes through the statement. What he doesn’t tell you at this point is that this is a bit like a long division version of a collision statement that is also built into RayLib. Later, once you understand what this does you will be instructed to just use the function that calculates it for you.

1 Like

It’d be a lot of extra code to write if you did if-else to achieve this, and since if-else is hierarchical in nature and we want any of those to be true for a successfully detected collision it would be impractical to do so.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms