c 2b 2b 2d rectangle collision

Solutions on MaxInterview for c 2b 2b 2d rectangle collision by the best coders in the world

showing results for - "c 2b 2b 2d rectangle collision"
Henry
05 Jul 2016
1var rect1 = {x: 5, y: 5, width: 50, height: 50}
2var rect2 = {x: 20, y: 10, width: 10, height: 10}
3
4if (rect1.x < rect2.x + rect2.width &&
5   rect1.x + rect1.width > rect2.x &&
6   rect1.y < rect2.y + rect2.height &&
7   rect1.height + rect1.y > rect2.y) {
8    // collision détectée !
9}