-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyOwnLibrary.js
More file actions
30 lines (22 loc) · 922 Bytes
/
Copy pathMyOwnLibrary.js
File metadata and controls
30 lines (22 loc) · 922 Bytes
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
27
28
29
30
function bounceOff(object1,object2){
if(object1.x - object2.x < object2.width/2 + object1.width/2 &&
object2.x-object1.x<object2.width/2+object1.width/2) {
object1.velocityX = object1.velocityX *(-1)
object2.velocityX = object2.velocityX *(-1)
}
if(object1.y-object2.y<object2.height/2+object1.height/2 &&
object2.y-object1.y<object1.height/2+object1.height/2){
object1.velocityY = object1.velocityY *(-1)
object2.velocityY = object2.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-object1.y<object1.height/2+object1.height/2){
return true
}else {
return false
}
}