๐ฏ
Goal for this step Land on platforms with the falling-only rule, in clean C++.
1 Platforms: std::vector<sf::FloatRect> , ground plus ledges.
2 After moving: for each platform, if bounds intersect AND vy > 0 AND we came from above โ snap on top, vy = 0, onGround = true.
3 "Came from above": previous bottom (bottom โ vyยทdt) was at or above the platform top.
4 Draw them from the same rects with one reusable RectangleShape.
std::vector<sf::FloatRect> platforms = {
{0, 440, 800, 40}, {150, 340, 140, 16},
{380, 260, 140, 16}, {610, 180, 140, 16},
};
onGround = false;
sf::FloatRect pb = shape.getGlobalBounds();
for (auto& plat : platforms) {
if (pb.intersects(plat) && vy > 0
&& pb.top + pb.height - vy * dt <= plat.top + 1) {
shape.setPosition(pb.left, plat.top - pb.height);
vy = 0;
onGround = true;
}
}
Snap onto the platform you landed on:
โถ Check My Code
๐ก Hint: Standing on top means your bottom equals the platform top; kill the fall; you are grounded.
This landing check is your third language writing it. The condition that never changed isโฆ
A The platform colour
B Only land while FALLING (vy > 0), the rule that lets you jump up through ledges
C The vector type
Check Answer
โ
Correct! Next Step โ