-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
26 lines (24 loc) · 968 Bytes
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function BounceOff(fixedRect,movingRect)
{
if (movingRect.x - fixedRect.x < fixedRect.width/2 + movingRect.width/2
&& fixedRect.x - movingRect.x < fixedRect.width/2 + movingRect.width/2) {
movingRect.velocityX = movingRect.velocityX * (-1);
fixedRect.velocityX = fixedRect.velocityX * (-1);
}
if (movingRect.y - fixedRect.y < fixedRect.height/2 + movingRect.height/2
&& fixedRect.y - movingRect.y < fixedRect.height/2 + movingRect.height/2){
movingRect.velocityY = movingRect.velocityY * (-1);
fixedRect.velocityY = fixedRect.velocityY * (-1);
}
}
function isTouching(object1,object2){
if (object1.x - object2.x < object2.width/2 + object1.width/2
&& object2.x - object1.x < object2.width/2 + object1.width/2
&& object1.y - object2.y < object2.height/2 + object1.height/2
&& object2.y - object2.y < object2.height/2 + object1.height/2) {
return true;
}
else {
return false;
}
}