Skip to content

Commit

Permalink
Improved Collision
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemanth Kumar Veeranki committed Jul 29, 2016
1 parent 288d7cc commit 3e69135
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion javascript/flapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,24 @@ function stopFlappingBackgound(name) {

//Parameters are rects
function isOverlap(e1, e2) {
return (e1.top <= e2.bottom && e2.top <= e1.bottom && e1.right >= e2.left && e1.left <= e2.right);
rect1 = {
x:e1.left+e1.width/2,
y:e1.bottom+e1.height/2,
width:e1.width,
height:e1.height,
};
rect2 = {
x:e2.left+e2.width/2,
y:e2.bottom+e2.height/2,
width:e2.width,
height:e2.height,
};
if (rect1.x < rect2.x + rect2.width &&
rect1.x + rect1.width > rect2.x &&
rect1.y < rect2.y + rect2.height &&
rect1.height + rect1.y > rect2.y)
return true;
else return false;
}

function onCollision(){
Expand Down

0 comments on commit 3e69135

Please sign in to comment.