|
|
|
|
|
by alfon
1616 days ago
|
|
You beat me to it, haha, This is what I just did: function intersectRect(rectA, rectB) {
return !(
rectB.left >= rectA.right ||
rectB.right <= rectA.left ||
rectB.top >= rectA.bottom ||
rectB.bottom <= rectA.top
);
} const arc = document.getElementById("arc");
const ball = document.getElementById("ball"); setInterval(() => {
if (intersectRect(arc.getBoundingClientRect(), ball.getBoundingClientRect())) {
window.dispatchEvent(new KeyboardEvent('keypress', {
keyCode: 32,
}));
}
}, 10); My code seems to go on forever, closed the tab after it reached 60K |
|
Of course, for how delightfully simple this one is, your approach is definitely faster/better!