-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.js
More file actions
43 lines (35 loc) · 781 Bytes
/
block.js
File metadata and controls
43 lines (35 loc) · 781 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
31
32
33
34
35
36
37
38
39
40
41
42
43
var BLOCK_SIZE = 20
class Block {
constructor(startingGridPos, color) {
this.startingGridPos = startingGridPos
this.currentGridPos = startingGridPos
this.color = color
this.line = startingGridPos.y
}
draw() {
push()
let pos = this.currentGridPos;
fill(this.color)
stroke(color(0,0,0))
strokeWeight(2)
rect(pos.x * BLOCK_SIZE, pos.y * BLOCK_SIZE, BLOCK_SIZE)
pop()
}
moveDown() {
this.currentGridPos.y += 1
this.line++
}
moveLeft() {
this.currentGridPos.x -= 1
}
moveRight() {
this.currentGridPos.x += 1
}
moveUp() {
this.currentGridPos.y -= 1
this.line--
}
}
function show() {
draw()
}