-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
56 lines (53 loc) · 1.21 KB
/
sketch.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
55
56
// ? Setting default start values
function setup() {
createCanvas(widthCanvas, heigthCanvas);
frameRate(framerate)
next()
holding = false
heldPiece = null
piece = new Piece()
board = new Board()
}
// ? Runs every frame
function draw() {
background(0);
if (keyIsDown(DOWN_ARROW) && !piece.checkDownWardsCollision()) piece.update()
if(piece.checkDownWardsCollision()) {
buffer--
if (buffer === 0) {
buffer = 10
piece.collideDownWards()
board.getClearedLines()
if (board.usedPlaces.some(place => place[2] === 0)) {
gameOver()
highscore = max(score, highscore)
noLoop()
} else {
piece = new Piece(nextPieceIndex)
next()
}
holding = false
}
} else {
buffer = 10
piece.update()
}
board.show()
piece.show()
nextPiece.show()
if(heldPiece) heldPiece.show()
push()
fill(255)
textSize(20)
text('Next:', 12 * gridSize, 1.5 * gridSize)
text('Hold:', 12 * gridSize, 12.5 * gridSize)
stroke(255)
noFill()
square(12 * gridSize, 2 * gridSize, 5 * gridSize)
square(12 * gridSize, 13 * gridSize, 5 * gridSize)
pop()
showScore()
}
function keyPressed() {
piece.receiveInput(key)
}