-
Notifications
You must be signed in to change notification settings - Fork 61
/
Block.js
35 lines (30 loc) · 891 Bytes
/
Block.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
27
28
29
30
31
32
33
34
35
class Block{
constructor(startingGridPos, color) {
this.startingGridPos = startingGridPos;
this.currentGridPos = startingGridPos;
this.color = color;
this.isDead = false;
}
clone(){
let clone = new Block(this.startingGridPos.copy(),this.color);
clone.isDead = this.isDead;
clone.currentGridPos = this.currentGridPos.copy();
return clone;
}
draw(tetrised = false, linesToBeCleared = []){
if(this.isDead)
return;
push();
let pos = this.currentGridPos;
if(tetrised && linesToBeCleared.includes(this.currentGridPos.y)){
stroke(0);
fill(255);
}else{
fill(this.color);
stroke(0);
}
strokeWeight(3);
rect(pos.x*BLOCK_SIZE,pos.y*BLOCK_SIZE,BLOCK_SIZE,BLOCK_SIZE);
pop();
}
}