0

for a simple rectangle, i would use:

if(ballX > rectX && ballX < rectX + rectWidth && ballY > rectY && ballY <rectY  + rectHeight) {
alert("Game over");
}
doubleOrt
  • 2,407
  • 1
  • 14
  • 34

1 Answers1

0

Your questions isn't really a javascript or html question directly but..

1) There are multiple options how to detect if two objects are colliding. One (and simple) solution is called AABB Collision Detection (good video tutorial)

2) There is a good Answer already on stackoverflow: Collision detection with complex shapes

3) There are plenty of good game frameworks (take a look at this list) doing collision detection for you. Are you sure you want to do it by your own?

Community
  • 1
  • 1
Daniel Bauer
  • 168
  • 2
  • 12