| Option name | Type | Description |
|---|---|---|
| X1 | Number | X coordinate of top left corner of first object |
| Y1 | Number | Y coordinate of top left corner of first object |
| Width | Number | Width of first object |
| Height | Number | Height of first object |
| X2 | Number | X coordinate of top left corner of second object |
| Y2 | Number | Y coordinate of top left corner of second object |
| Width2 | Number | Width of second object |
| Height2 | Number | Height of second object |
| return | Boolean | Whether or not two rectangles have collided |
Axis aligned bounding box collision check
collision.AABB = function(x1, y1, w1, h1, x2, y2, w2, h2) {
return (x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && h1 + y1 > y2);
}
| Option name | Type | Description |
|---|---|---|
| X | Number | X coordinate of center of first object |
| Y | Number | Y coordinate of center of first object |
| Radius | Number | Radius of first object |
| X | Number | X coordinate of center of second object |
| Y | Number | Y coordinate of center of second object |
| Radius | Number | Radius of second object |
| return | Boolean | Whether or not two circles have collided |
Bounding circle collision check
collision.circle = function(x1, y1, r1, x2, y2, r2) {
return (x2-x1)^2 + (y1-y2)^2 <= (r1+r2)^2;
}
module.exports = collision;