-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbox.js
More file actions
66 lines (56 loc) · 1.54 KB
/
Copy pathbox.js
File metadata and controls
66 lines (56 loc) · 1.54 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Box {
constructor(x, y, width, height, colour) {
var options = {
//restitution: 0.1,
//density: 0.8,
friction: 0.1
}
this.body = Bodies.rectangle(x, y, width, height, options);
World.add(world, this.body);
this.width = width;
this.height = height;
this.colour = colour;
this.visibility = 255;
}
display() {
var pos = this.body.position;
var angle = this.body.angle;
if (pos.y < 700) {
push();
fill(this.colour);
translate(pos.x, pos.y);
rotate(angle);
stroke(0, 0, 0);
rect(0, 0, this.width, this.height);
pop();
}
else {
push();
this.boxColour = color(this.colour);
this.boxColour.setAlpha(this.visibility);
fill(this.boxColour);
translate(pos.x, pos.y);
rotate(angle);
noStroke();
rect(pos.x, pos.y, this.width, this.height);
this.visibility -= 5;
World.remove(world, this.body);
pop();
this.checkVisibility();
}
}
checkVisibility(){
if(this.visibility === 5){
boxFallenArray.push(true);
}
else{
boxFallenArray.push(false);
}
}
showScore() {
displayText('Score: ' + score, 1050, 50, 'red', 30);
if(this.visibility > 0 && this.visibility < 20){
score++;
}
}
}