forked from fanta500/TetrisP5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.js
54 lines (44 loc) · 1.11 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Block {
constructor(positionX, positionY, blockSize, color) {
this.defaultX = positionX;
this.defaultY = positionY;
this.x = positionX;
this.y = positionY;
this.blockSize = blockSize;
this.color = color;
}
draw() {
fill(this.color)
rect(this.x, this.y, this.blockSize, this.blockSize)
}
drawNextShape(offset) {
fill(this.color)
rect(this.x + offset, this.y + offset/4, this.blockSize, this.blockSize)
}
drawHeldShape(offset) {
fill(this.color)
rect(this.defaultX + offset, this.defaultY - offset/4, this.blockSize, this.blockSize) //offset param passed here is negative as a precondition, hence minus offset for y coord
}
getX() {
return this.x;
}
getY() {
return this.y
}
setX(newX) {
this.x = newX;
}
setY(newY) {
this.y = newY;
}
getDefaultX() {
return defaultX;
}
getDefaultY() {
return defaultY;
}
resetPosition() {
this.x = this.defaultX;
this.y = this.defaultY;
}
}