I am currently trying to replicate frogger and am struggling with the collision detection in relation to both the water and the logs.
I can have it so if the frog jumps on the log it is carried with the log, and I can also have the frog respawn if it collides with the water, but I can't have both. When I try it just takes the water collision over anything else.
This may be because the water is one large rectangle with the logs on top being smaller rectangles but the size of logs and the movement make it so the frog sits flush on the log.
for (size_t i = 0; i < viLogS.size(); i++)
{
if (viLogS[i].getGlobalBounds().intersects(player.getGlobalBounds()))
{
player.move(-2, 0); //if frog and log intersect move frog along same axis and speed as log
}
else if (waterzone.waterRectangle.getGlobalBounds().intersects(player.getGlobalBounds()))
{
player.FrogRespawn();
}
}
intersectmethod return a reference to a intersection rectangle (in this case it always returns true, also for an empty rectangle ---you have to check this) or is a predicate, in the sense that it saystrueorfalseif it intersects. Have the rectangle class a boolean cast that maps allows you to check for emptyness? - Luis Colorado