little fixes

This commit is contained in:
Adrien MALINGREY 2019-10-30 22:35:01 +01:00
parent 40911443ed
commit 1577fb5dbf

View File

@ -429,6 +429,7 @@ function generationPhase(held_piece=null) {
nextQueue.pieces.push(new Tetromino()) nextQueue.pieces.push(new Tetromino())
nextQueue.pieces.forEach((piece, i) => piece.pos = NEXT_PIECES_POSITIONS[i]) nextQueue.pieces.forEach((piece, i) => piece.pos = NEXT_PIECES_POSITIONS[i])
} }
nextQueue.draw()
matrix.piece.pos = FALLING_PIECE_POSITION matrix.piece.pos = FALLING_PIECE_POSITION
if (matrix.spaceToMove(matrix.piece.minoesPos.translate(matrix.piece.pos))){ if (matrix.spaceToMove(matrix.piece.minoesPos.translate(matrix.piece.pos))){
scheduler.clearInterval(lockPhase) scheduler.clearInterval(lockPhase)
@ -441,6 +442,7 @@ function generationPhase(held_piece=null) {
function fallingPhase() { function fallingPhase() {
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
matrix.piece.locked = false matrix.piece.locked = false
matrix.draw()
} }
function lockPhase() { function lockPhase() {
@ -448,8 +450,8 @@ function lockPhase() {
matrix.piece.locked = true matrix.piece.locked = true
if (!scheduler.timeoutTasks.has(lockDown)) if (!scheduler.timeoutTasks.has(lockDown))
scheduler.setTimeout(lockDown, stats.lockDelay) scheduler.setTimeout(lockDown, stats.lockDelay)
matrix.draw()
} }
requestAnimationFrame(draw)
} }
function move(movement, testMinoesPos=matrix.piece.minoesPos) { function move(movement, testMinoesPos=matrix.piece.minoesPos) {
@ -466,6 +468,7 @@ function move(movement, testMinoesPos=matrix.piece.minoesPos) {
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
scheduler.setTimeout(lockDown, stats.lockDelay) scheduler.setTimeout(lockDown, stats.lockDelay)
} }
matrix.draw()
return true return true
} else { } else {
return false return false
@ -520,7 +523,7 @@ function lockDown(){
}) })
stats.lockDown(tSpin, matrix.clearedLines.length) stats.lockDown(tSpin, matrix.clearedLines.length)
requestAnimationFrame(draw) matrix.draw()
scheduler.setTimeout(clearLinesCleared, ANIMATION_DELAY) scheduler.setTimeout(clearLinesCleared, ANIMATION_DELAY)
if (stats.goal <= 0) if (stats.goal <= 0)
@ -532,7 +535,7 @@ function lockDown(){
function clearLinesCleared() { function clearLinesCleared() {
matrix.clearedLines = [] matrix.clearedLines = []
requestAnimationFrame(draw) matrix.draw()
} }
function gameOver() { function gameOver() {
@ -541,7 +544,6 @@ function gameOver() {
scheduler.clearInterval(lockPhase) scheduler.clearInterval(lockPhase)
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
scheduler.clearInterval(clock) scheduler.clearInterval(clock)
requestAnimationFrame(draw)
if (stats.score == stats.highScore) { if (stats.score == stats.highScore) {
alert("Bravo !\nVous avez battu votre précédent record.") alert("Bravo !\nVous avez battu votre précédent record.")
@ -552,7 +554,6 @@ function gameOver() {
function autorepeat() { function autorepeat() {
if (actionsToRepeat.length) { if (actionsToRepeat.length) {
actionsToRepeat[0]() actionsToRepeat[0]()
requestAnimationFrame(draw)
if (scheduler.timeoutTasks.has(autorepeat)) { if (scheduler.timeoutTasks.has(autorepeat)) {
scheduler.clearTimeout(autorepeat) scheduler.clearTimeout(autorepeat)
scheduler.setInterval(autorepeat, AUTOREPEAT_PERIOD) scheduler.setInterval(autorepeat, AUTOREPEAT_PERIOD)
@ -571,7 +572,6 @@ function keyDownHandler(e) {
if (e.key in actions[state]) { if (e.key in actions[state]) {
action = actions[state][e.key] action = actions[state][e.key]
action() action()
requestAnimationFrame(draw)
if (REPEATABLE_ACTIONS.includes(action)) { if (REPEATABLE_ACTIONS.includes(action)) {
actionsToRepeat.unshift(action) actionsToRepeat.unshift(action)
scheduler.clearTimeout(autorepeat) scheduler.clearTimeout(autorepeat)
@ -626,7 +626,7 @@ function hardDrop() {
function clearTrail() { function clearTrail() {
matrix.trail.height = 0 matrix.trail.height = 0
requestAnimationFrame(draw) matrix.draw()
} }
function rotateCW() { function rotateCW() {
@ -638,14 +638,16 @@ function rotateCCW() {
} }
function hold() { function hold() {
if (this.matrix.piece.holdEnabled) { if (matrix.piece.holdEnabled) {
scheduler.clearInterval(move) scheduler.clearInterval(move)
scheduler.clearInterval(lockDown) scheduler.clearInterval(lockDown)
var shape = this.matrix.piece.shape var shape = matrix.piece.shape
this.matrix.piece = this.holdQueue.piece matrix.piece = holdQueue.piece
this.holdQueue.piece = new Tetromino(HELD_PIECE_POSITION, shape) holdQueue.piece = new Tetromino(HELD_PIECE_POSITION, shape)
this.holdQueue.piece.holdEnabled = false holdQueue.piece.holdEnabled = false
this.generationPhase(this.matrix.piece) holdQueue.draw()
generationPhase(matrix.piece)
matrix.piece.holdEnabled = false
} }
} }
@ -657,6 +659,9 @@ function pause() {
scheduler.clearTimeout(lockDown) scheduler.clearTimeout(lockDown)
scheduler.clearTimeout(autorepeat) scheduler.clearTimeout(autorepeat)
scheduler.clearInterval(clock) scheduler.clearInterval(clock)
hold.draw()
matrix.draw()
next.draw()
} }
function resume() { function resume() {
@ -666,8 +671,10 @@ function resume() {
scheduler.setTimeout(lockPhase, stats.fallPeriod) scheduler.setTimeout(lockPhase, stats.fallPeriod)
if (matrix.piece.locked) if (matrix.piece.locked)
scheduler.setTimeout(lockDown, stats.lockDelay) scheduler.setTimeout(lockDown, stats.lockDelay)
requestAnimationFrame(draw)
scheduler.setInterval(clock, 1000) scheduler.setInterval(clock, 1000)
hold.draw()
matrix.draw()
next.draw()
} }
function printTempTexts(texts) { function printTempTexts(texts) {
@ -688,12 +695,6 @@ function delTempTexts(self) {
} }
} }
function draw() {
holdQueue.draw()
matrix.draw()
nextQueue.draw()
}
function getKey(action) { function getKey(action) {
return localStorage.getItem(action) || actionsDefaultKeys[action] return localStorage.getItem(action) || actionsDefaultKeys[action]
} }