I'm trying to build a game where the user should place the circle inside a vertical bar but I'm having trouble in the collision detection function. Here is my jsfiddle : http://jsfiddle.net/seekpunk/QnBhK/1/
if (collides(Bluecircle, longStand)) {
Bluecircle.y = longStand.y2;
Bluecircle.x = longStand.x2;
}
else if (collides(Bluecircle, ShortStand)) {
Bluecircle.y = ShortStand.y2;
Bluecircle.x = ShortStand.x2;
}
function collides(a, bar) {
return a.x == bar.x1 && a.y == bar.y1;
}
See Question&Answers more detail:os