-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLava.js
More file actions
executable file
·37 lines (36 loc) · 1.04 KB
/
Lava.js
File metadata and controls
executable file
·37 lines (36 loc) · 1.04 KB
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
31
32
33
34
35
36
37
class Lava extends Coin{ //Default starting coordinates = (92,7)
constructor(x,y, distance = 0){
super()
this.gravID
this.defaultX = x
this.defaultY = y
this.x = x
this.y = y
this.distance = distance
this.width = 2
this.height = 2
this.color = "red"
drawRect(this.x, this.y, this.width, this.height, this.color)
this.surface = generateSurface(this.x, this.y, this.width, this.height)
}
gravity(...surface){ //Takes surfaces.. Returns false when surface is encountered and loop terminates
this.gravID = setInterval(() => {
if((this.distance!=0)&&(this.x==this.defaultX)&&(this.y==this.defaultY + this.distance)){
this.move(this.defaultX, this.defaultY)
} else{
let holder = 0
for (let i = 0; i < surface[0].length; i++){
if(!overlap(surface[0][i], this.checkSurface(this.x, this.y+1))){
holder++
}
}
if(holder == surface[0].length){
this.move(this.x, this.y+1)
}
else{ //resets when it meets an obstacle
this.move(this.defaultX, this.defaultY)
}
}
}, 80);
}
}