1
- let grey = " #6e6e6e" ;
1
+ let grey = ' #6e6e6e' ;
2
2
let colors = [
3
- " #f02011" ,
4
- " #f07211" ,
5
- " #f0c311" ,
6
- " #c7f011" ,
7
- " #11ecf0" ,
8
- " #1172f0" ,
9
- " #b511f0" ,
10
- " #f0118c" ,
3
+ ' #f02011' ,
4
+ ' #f07211' ,
5
+ ' #f0c311' ,
6
+ ' #c7f011' ,
7
+ ' #11ecf0' ,
8
+ ' #1172f0' ,
9
+ ' #b511f0' ,
10
+ ' #f0118c' ,
11
11
] ;
12
12
13
13
class Tetris {
14
14
constructor ( sizeX , sizeY ) {
15
- this . highScore = localStorage . getItem ( " highscore" ) || 0 ;
15
+ this . highScore = localStorage . getItem ( ' highscore' ) || 0 ;
16
16
this . sizeX = sizeX ;
17
17
this . sizeY = sizeY ;
18
18
@@ -205,7 +205,6 @@ class Tetris {
205
205
this . nextActiveMaterial = random ( colors ) ;
206
206
this . nextActiveType = floor ( random ( 6 ) ) ;
207
207
this . nextActiveCoord = createVector ( this . sizeX / 2 , 1 ) ;
208
- this . renderActive ( ) ;
209
208
}
210
209
211
210
render ( ) {
@@ -231,16 +230,12 @@ class Tetris {
231
230
push ( ) ;
232
231
fill ( 255 ) ;
233
232
textSize ( this . scale * 1.1 ) ;
234
- text ( " Next" , - this . scale * 6.5 , this . scale * 1.5 ) ;
233
+ text ( ' Next' , - this . scale * 6.5 , this . scale * 1.5 ) ;
235
234
pop ( ) ;
236
235
237
- let coords = this . getCoords (
238
- this . nextActiveType ,
239
- this . nextActiveCoord ,
240
- 0
241
- ) ;
236
+ const coords = this . getCoords ( this . nextActiveType , this . nextActiveCoord , 0 ) ;
242
237
243
- for ( let coord of coords ) {
238
+ for ( const coord of coords ) {
244
239
Cell . render (
245
240
coord . x - 10.5 ,
246
241
coord . y + 3 ,
@@ -283,20 +278,19 @@ class Tetris {
283
278
if ( dir == LEFT || dir == RIGHT ) return ;
284
279
this . applyBoxes ( before ) ;
285
280
this . spawn ( ) ;
286
- this . update ( ) ;
281
+ // this.update();
287
282
return ;
288
283
}
289
284
let intersects = this . checkIntersection ( after ) ;
290
285
if ( intersects == SPAWN ) {
291
286
if ( dir == LEFT || dir == RIGHT ) return ;
292
287
this . applyBoxes ( before ) ;
293
288
this . spawn ( ) ;
294
- this . update ( ) ;
289
+ // this.update();
295
290
return ;
296
291
}
297
292
298
293
this . activeCoord = newCoord ;
299
- this . renderActive ( ) ;
300
294
}
301
295
302
296
applyBoxes ( coords ) {
@@ -391,7 +385,7 @@ class Tetris {
391
385
}
392
386
393
387
rotate ( rot ) {
394
- let wall = this . checkWallOnRotation ( ) ;
388
+ const wall = this . checkWallOnRotation ( ) ;
395
389
if ( wall == WALL ) return ;
396
390
let after = this . rotation ;
397
391
@@ -402,16 +396,16 @@ class Tetris {
402
396
after = this . shapesOffsets [ this . activeType ] . length - 1 ;
403
397
}
404
398
405
- let coords = this . getCoords ( this . activeType , this . activeCoord , after ) ;
406
- let intersects = this . checkIntersection ( coords ) ;
399
+ const coords = this . getCoords ( this . activeType , this . activeCoord , after ) ;
400
+ const intersects = this . checkIntersection ( coords ) ;
407
401
408
402
if ( intersects == SPAWN ) return ;
409
403
410
404
this . rotation = after ;
411
405
}
412
406
413
407
getCoords ( type , center , rotation ) {
414
- let result = [ ] ;
408
+ const result = [ ] ;
415
409
for ( let i = 0 ; i < this . shapesOffsets [ type ] [ rotation ] . length ; i ++ ) {
416
410
let offset = this . shapesOffsets [ type ] [ rotation ] [ i ] ;
417
411
result . push ( createVector ( offset . x + center . x , offset . y + center . y ) ) ;
@@ -457,13 +451,13 @@ class Tetris {
457
451
}
458
452
459
453
hardDropCoords ( ) {
460
- let coords = this . getCoords (
454
+ const coords = this . getCoords (
461
455
this . activeType ,
462
456
this . activeCoord ,
463
457
this . rotation
464
458
) ;
465
459
let minDistance = this . sizeY ;
466
- for ( let coord of coords ) {
460
+ for ( const coord of coords ) {
467
461
let hit = false ;
468
462
for ( let i = coord . y + 1 ; i < this . boxes . length ; i ++ ) {
469
463
for ( let j = 0 ; j < this . boxes [ i ] . length ; j ++ ) {
@@ -489,32 +483,32 @@ class Tetris {
489
483
updateHighScore ( ) {
490
484
if ( this . score > this . highScore ) {
491
485
this . highScore = this . score ;
492
- localStorage . setItem ( " highscore" , this . score ) ;
486
+ localStorage . setItem ( ' highscore' , this . score ) ;
493
487
}
494
488
}
495
489
496
490
hardDrop ( ) {
497
491
let coords = this . hardDropCoords ( ) ;
498
492
this . applyBoxes ( coords ) ;
499
493
this . spawn ( ) ;
500
- this . update ( ) ;
494
+ // this.update();
501
495
}
502
496
503
497
updateStats ( ) {
504
498
push ( ) ;
505
499
fill ( 255 ) ;
506
500
textSize ( this . scale * 1.1 ) ;
507
501
let xPos = this . width + this . scale * 3 ;
508
- text ( " Score" , xPos , this . scale * 1.5 ) ;
509
- text ( " Lines" , xPos , this . scale * 3.5 ) ;
510
- text ( " Level" , xPos , this . scale * 5.5 ) ;
502
+ text ( ' Score' , xPos , this . scale * 1.5 ) ;
503
+ text ( ' Lines' , xPos , this . scale * 3.5 ) ;
504
+ text ( ' Level' , xPos , this . scale * 5.5 ) ;
511
505
textSize ( this . scale ) ;
512
506
fill ( color ( colors [ 3 ] ) ) ;
513
- text ( "" + this . score , xPos , this . scale * 2.5 ) ;
507
+ text ( '' + this . score , xPos , this . scale * 2.5 ) ;
514
508
fill ( color ( colors [ 1 ] ) ) ;
515
- text ( "" + this . lines , xPos , this . scale * 4.5 ) ;
509
+ text ( '' + this . lines , xPos , this . scale * 4.5 ) ;
516
510
fill ( color ( colors [ 0 ] ) ) ;
517
- text ( "" + this . level , xPos , this . scale * 6.5 ) ;
511
+ text ( '' + this . level , xPos , this . scale * 6.5 ) ;
518
512
pop ( ) ;
519
513
}
520
514
}
0 commit comments