Workshop › Mario-style Platformer › Step 23 of 37
Collecting is a box overlap between the player and each coin not yet taken. Two boxes overlap when each one starts before the other one ends, on both axes.
```js
function overlaps(a, b) {
return a.x < b.x + b.w && a.x + a.w > b.x && a.y < b.y + b.h && a.y + a.h > b.y
}
for (const coin of coins) {
if (!coin.taken && overlaps(player, coin)) {
coin.taken = true
}
}
```a.x < b.x + b.w: A starts before B ends; a.x + a.w > b.x: A ends after B starts. The same for y. All four: overlap.update, every coin that is not taken and overlaps the player becomes taken, so it is no longer drawn.// Move along one axis ... comment write overlaps, with an empty line after it.update, under updatePlayer(), leave an empty line and write the coin loop.Skills: Collision detection
← Coins Count, and screen versus world →