2
\$\begingroup\$

I am making a Frogger game in C++ using SFML but have come across a problem. I have a block of water and log rectangles moving over it (All sprites) and would like the Frog sprite to do something when it hits the water, however with bounding boxes, even in the frog sprite moves onto a log it still passes the water bounding box and carries out the code for that. Is there any way to have the conditions so it intersects the water but only does something when it's not in collision with the log's?

Thank you.

\$\endgroup\$
0
\$\begingroup\$

One way to do it would be to wait until all your collision detection is done before 'reacting' to it. You could then check if it touches only the water and not the log before 'reacting' to the event.

Example game loop:

  1. Update from user imput
  2. Move your game objects
  3. Clear frog-water collision flag and frog-log collision flag
  4. Perform collision detection
    1. Raise a flag if there is a frog-water collision
    2. Raise a flag if there is a frog-log collision
  5. React to physics
    1. Perform the 'on hit water' code if frog-water collision flag is raised and frog-log collision flag is not raised

Obviously, this will depend on your implementation, but this could give you an idea on how it could be done.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.