-
-
Save parzibyte/8dfe5e82281e1203a1d725e821a03799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mainLoop() { | |
if (!this.canPlay) { | |
return; | |
} | |
// If figure can move down, move down | |
if (this.figureCanMoveDown()) { | |
this.globalY++; | |
} else { | |
// If figure cannot, then we start a timeout because | |
// player can move figure to keep it going down | |
// for example when the figure collapses with another points but there's remaining | |
// space at the left or right and the player moves there so the figure can keep going down | |
if (this.timeoutFlag) return; | |
this.timeoutFlag = true; | |
setTimeout(() => { | |
this.timeoutFlag = false; | |
// If the time expires, we re-check if figure cannot keep going down. If it can | |
// (because player moved it) then we return and keep the loop | |
if (this.figureCanMoveDown()) { | |
return; | |
} | |
// At this point, we know that the figure collapsed either with the floor | |
// or with another point. So we move all the figure to the existing pieces array | |
this.sounds.tap.currentTime = 0; | |
this.sounds.tap.play(); | |
this.moveFigurePointsToExistingPieces(); | |
if (this.playerLoses()) { | |
Swal.fire("Juego terminado", "Inténtalo de nuevo"); | |
this.sounds.background.pause(); | |
this.canPlay = false; | |
this.resetGame(); | |
return; | |
} | |
this.verifyAndDeleteFullRows(); | |
this.chooseRandomFigure(); | |
this.syncExistingPiecesWithBoard() | |
}, Game.TIMEOUT_LOCK_PUT_NEXT_PIECE); | |
} | |
this.syncExistingPiecesWithBoard(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment