Not understanding Collision_with_axe condition

I’m taking c++ fundamental:Game Programmer for beginner. Finishing the game video in that course, collision_with_axe condition is so confusing to me.Can you explain the details.Please, thank you. :pray: :blush:

Hi Kyaw,

To help me have a starting point for explaining the collision with the axe, can you tell me what you find confusing about it?

bool collision_with_axe = (b_axe_y >= u_circle_y) && (u_axe_y <= b_circle_y) && (l_axe_x <= r_circle_x) && (r_axe_x >= l_circle_x)

why we set this condition?:pray:

With that expression we’re trying to see if the player (represented by the circle) is sharing the same space as the axe (represented by the square). We consider this sharing of space a “collision”.

To do this, we wrap each object in an invisible square that has edges placed at the ends of each object. Those edges are then tested against each other to see if they are overlapping which signifies that space is being shared between them.

We then store the result of that test into collision_with_axe. If the result is true, we end the game. If it is false, the game keeps going.

1 Like

thank you :blush: :pray:

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

Privacy & Terms