Why both axes must overlap
Two rectangles can be at the same height but far apart, or stacked but far apart, either way they don't touch. The test catches "far away" in a single line because it requires overlap on both axes.
// Same height, separated horizontally → X fails
A = {x:100,y:100,w:40,h:56}, B = {x:500,y:110,w:20,h:20}
// A.x + A.w > B.x → 140 > 500 → false
// Stacked vertically, separated → Y fails
A = {x:100,y:100,w:40,h:56}, B = {x:110,y:500,w:20,h:20}
// A.y + A.h > B.y → 156 > 500 → false
This is the whole reason the game has no rotation: an axis-aligned rectangle has clean left/right/top/bottom edges, so overlap reduces to comparing four edges. Rotated objects would need real geometry, which a platformer never wants.
Fairness in the hitbox
Collision isn't just correct, it's fair. The game gives the player a smaller hurtRect for hazards than the full rect for coins. A sliding player's hurtbox shrinks even further, so a narrowly-grazing spike doesn't kill you.
// Coins use the full body;
// hazards use a smaller, more forgiving hurt box.
player.hurtRect = { x: x+6, y: y+8, w: w-12, h: h-16 };
This is the same spirit as the difficulty caps: the game is hard but winnable, and a death should be the player's fault, never the game's. We prove exactly this with tests in the Master tier.
A classic beginner mistake is to make the player's hitbox exactly their drawn body while the obstacle's is larger, that biases collisions against the player and feels unfair.