-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.js
104 lines (92 loc) · 1.65 KB
/
global.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const gridSize = 30 // ? Size (pixels) of a square in the grid
const widthCanvas = 19 * gridSize
const heigthCanvas = 20 * gridSize
const widthBoard = 10 * gridSize
const heightBoard = 20 * gridSize
const framerate = 30
const velocity = gridSize / 5 // ? Must be an integer submultiple of gridSize
const scoreCounter = document.querySelector('#score')
const highScoreCounter = document.querySelector('#highscore')
const gameOverScreen = document.querySelector('.gameover-screen')
const restartBtn = document.querySelector('.gameover-btn')
let score = 0
let highscore = 0
let holding = false
let nextPieceIndex
let heldPieceIndex
let buffer = 10
// ? pIndex and name properties are not actually used anywhere,
// ? they here only to make it easier to know a piece's shape without looking at the matrix and
// ? relate each piece with its index in the pieces array
const pieces = [
{
pIndex: 0,
name: 'O',
color: '#FCFF4D',
matrix: [
[1, 1],
[1, 1]
]
},
{
pIndex: 1,
name: 'Z',
color: '#E30013',
matrix: [
[0, 0, 0],
[1, 1, 0],
[0, 1, 1]
]
},
{
pIndex: 2,
name: 'S',
color: '#5EFF4A',
matrix: [
[0, 0, 0],
[0, 1, 1],
[1, 1, 0]
]
},
{
pIndex: 3,
name: 'T',
color: '#F924FE',
matrix: [
[0, 0, 0],
[1, 1, 1],
[0, 1, 0]
]
},
{
pIndex: 4,
name: 'J',
color: '#0050FF',
matrix: [
[0, 1, 0],
[0, 1, 0],
[1, 1, 0]
]
},
{
pIndex: 5,
name: 'L',
color: '#F7871A',
matrix: [
[0, 1, 0],
[0, 1, 0],
[0, 1, 1]
]
},
{
pIndex: 6,
name: 'I',
color: '#69FFFE',
matrix: [
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0]
]
}
]