You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main.js
+157-83
Original file line number
Diff line number
Diff line change
@@ -1,47 +1,11 @@
1
1
varcanvas=document.getElementById("game")
2
2
varctx=canvas.getContext("2d")
3
+
ctx.globalAlpha=1
3
4
varcanvas2=document.getElementById("next")
4
5
varctx2=canvas2.getContext("2d")
5
6
varcanvas3=document.getElementById("store")
6
7
varctx3=canvas3.getContext("2d")
7
8
vardefurl='https://coderpro1234-2.github.io'
8
-
varfx=0
9
-
varfy=0
10
-
varnxtt=0
11
-
varmusicplay=0
12
-
vartimer=0
13
-
varuseswap=false
14
-
varrunning=true
15
-
varinstout=false
16
-
constgblocks=[
17
-
0,0,0,0,0,0,0,0,0,0,
18
-
0,0,0,0,0,0,0,0,0,0,
19
-
0,0,0,0,0,0,0,0,0,0,
20
-
0,0,0,0,0,0,0,0,0,0,
21
-
0,0,0,0,0,0,0,0,0,0,
22
-
0,0,0,0,0,0,0,0,0,0,
23
-
0,0,0,0,0,0,0,0,0,0,
24
-
0,0,0,0,0,0,0,0,0,0,
25
-
0,0,0,0,0,0,0,0,0,0,
26
-
0,0,0,0,0,0,0,0,0,0,
27
-
0,0,0,0,0,0,0,0,0,0,
28
-
0,0,0,0,0,0,0,0,0,0,
29
-
0,0,0,0,0,0,0,0,0,0,
30
-
0,0,0,0,0,0,0,0,0,0,
31
-
0,0,0,0,0,0,0,0,0,0,
32
-
0,0,0,0,0,0,0,0,0,0,
33
-
0,0,0,0,0,0,0,0,0,0,
34
-
0,0,0,0,0,0,0,0,0,0,
35
-
0,0,0,0,0,0,0,0,0,0,
36
-
0,0,0,0,0,0,0,0,0,0
37
-
]
38
-
fblock=[
39
-
0,0,0,0,
40
-
0,0,0,0,
41
-
0,0,0,0,
42
-
0,0,0,0
43
-
]
44
-
sblock=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
45
9
consttetrominoes=[
46
10
[0,5,0,0,0,5,0,0,0,5,0,0,0,5,0,0],
47
11
[0,0,0,0,0,3,3,0,0,3,3,0,0,0,0,0],
@@ -51,10 +15,63 @@ const tetrominoes = [
51
15
[0,0,0,0,0,0,6,0,0,0,6,0,0,6,6,0],
52
16
[0,0,0,0,7,7,7,0,0,7,0,0,0,0,0,0]
53
17
]
18
+
varfx=0
19
+
varfy=0
20
+
varnxtt=0
21
+
varmusicplay=0
22
+
vartimer=0
23
+
varlines=0
24
+
varscore=0
25
+
varuseswap=true
26
+
varrunning=true
27
+
varinstout=true
28
+
gblocks=[]
29
+
fblock=[]
30
+
sblock=[]
31
+
nxtt=0
32
+
functionreset_vars(){
33
+
fx=0
34
+
fy=0
35
+
nxtt=0
36
+
lines=0
37
+
score=0
38
+
useswap=false
39
+
running=true
40
+
instout=false
41
+
gblocks=[
42
+
0,0,0,0,0,0,0,0,0,0,
43
+
0,0,0,0,0,0,0,0,0,0,
44
+
0,0,0,0,0,0,0,0,0,0,
45
+
0,0,0,0,0,0,0,0,0,0,
46
+
0,0,0,0,0,0,0,0,0,0,
47
+
0,0,0,0,0,0,0,0,0,0,
48
+
0,0,0,0,0,0,0,0,0,0,
49
+
0,0,0,0,0,0,0,0,0,0,
50
+
0,0,0,0,0,0,0,0,0,0,
51
+
0,0,0,0,0,0,0,0,0,0,
52
+
0,0,0,0,0,0,0,0,0,0,
53
+
0,0,0,0,0,0,0,0,0,0,
54
+
0,0,0,0,0,0,0,0,0,0,
55
+
0,0,0,0,0,0,0,0,0,0,
56
+
0,0,0,0,0,0,0,0,0,0,
57
+
0,0,0,0,0,0,0,0,0,0,
58
+
0,0,0,0,0,0,0,0,0,0,
59
+
0,0,0,0,0,0,0,0,0,0,
60
+
0,0,0,0,0,0,0,0,0,0,
61
+
0,0,0,0,0,0,0,0,0,0
62
+
]
63
+
fblock=[
64
+
0,0,0,0,
65
+
0,0,0,0,
66
+
0,0,0,0,
67
+
0,0,0,0
68
+
]
69
+
sblock=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
70
+
nxtt=randnumber(0,6)
71
+
}
54
72
functionrandnumber(min,max){
55
73
returnMath.floor(Math.random()*(max-min+1))+min;
56
74
}
57
-
nxtt=randnumber(0,6)
58
75
functioncheckmusic(){
59
76
if(musicplay==0){
60
77
tetrismusic.play()
@@ -143,6 +160,22 @@ function draw_store() {
143
160
i++
144
161
}
145
162
}
163
+
functiondraw_ghost(){
164
+
o_fy=fy
165
+
i=0
166
+
while(i!=-1){
167
+
fy=fy+1
168
+
if(f_coll_g()){
169
+
fy=fy-1
170
+
i=-2
171
+
}
172
+
i++
173
+
}
174
+
ctx.globalAlpha=0.5
175
+
draw_fblock()
176
+
ctx.globalAlpha=1
177
+
fy=o_fy
178
+
}
146
179
functiong_xy(x,y){
147
180
if(y>19||x<0||x>9){
148
181
return(1)
@@ -198,25 +231,54 @@ function sro(off, color) {
198
231
functionyou_died(){
199
232
c1=0
200
233
c2=0
201
-
setInterval(function(){
202
-
sro(c1,c2+1)
203
-
c1+=1
204
-
c2+=1
205
-
c2=c2%7
206
-
if(c1==20){
207
-
c1=0
208
-
c2=0
209
-
setTimeout(function(){
210
-
window.location.reload()
211
-
set_f(true)
212
-
},400)
234
+
constdeathinter=setInterval(function(){
235
+
if(running==false){
236
+
sro(c1,c2+1)
237
+
c1+=1
238
+
c2+=1
239
+
c2=c2%7
240
+
if(c1==20){
241
+
c1=0
242
+
c2=0
243
+
setTimeout(function(){
244
+
reset_vars()
245
+
running=true
246
+
gblocks=[
247
+
0,0,0,0,0,0,0,0,0,0,
248
+
0,0,0,0,0,0,0,0,0,0,
249
+
0,0,0,0,0,0,0,0,0,0,
250
+
0,0,0,0,0,0,0,0,0,0,
251
+
0,0,0,0,0,0,0,0,0,0,
252
+
0,0,0,0,0,0,0,0,0,0,
253
+
0,0,0,0,0,0,0,0,0,0,
254
+
0,0,0,0,0,0,0,0,0,0,
255
+
0,0,0,0,0,0,0,0,0,0,
256
+
0,0,0,0,0,0,0,0,0,0,
257
+
0,0,0,0,0,0,0,0,0,0,
258
+
0,0,0,0,0,0,0,0,0,0,
259
+
0,0,0,0,0,0,0,0,0,0,
260
+
0,0,0,0,0,0,0,0,0,0,
261
+
0,0,0,0,0,0,0,0,0,0,
262
+
0,0,0,0,0,0,0,0,0,0,
263
+
0,0,0,0,0,0,0,0,0,0,
264
+
0,0,0,0,0,0,0,0,0,0,
265
+
0,0,0,0,0,0,0,0,0,0,
266
+
0,0,0,0,0,0,0,0,0,0
267
+
]
268
+
set_f()
269
+
update_screen()
270
+
},400)
271
+
}
272
+
}
273
+
else{
274
+
clearInterval(deathinter)
275
+
return
213
276
}
214
-
},100)
215
-
277
+
},70)
216
278
}
217
279
functionswapinst(){
218
280
instout=!instout
219
-
txt="Instrunctions:<br>Up Arrow / W to snap block to bottom.<br>Left or Right Arrows / A or D to move block left or right.<br>Down Arrow / S to move block one tile down.<br> X to rotate block clockwise.<br>Z to rotate block counter-clockwise.<br>Q to save block to store if it is empty.<br>E to swap block from store if it exists."
281
+
txt="Instrunctions:<br>Up Arrow / W to snap block to bottom.<br>Left or Right Arrows / A or D to move block left or right.<br>Down Arrow / S to move block one tile down.<br> X to rotate block clockwise.<br>Z to rotate block counter-clockwise.<br>Q or E tp add or swap the block in the store."
0 commit comments