reset
This commit is contained in:
parent
efb6482238
commit
375d47397e
10
app.js
10
app.js
@ -62,7 +62,7 @@ let game = {
|
||||
if (settings.musicVolume) scene.music.play()
|
||||
|
||||
if (playfield.piece) {
|
||||
scheduler.setInterval(game.fall, stats.fallPeriod)
|
||||
scheduler.resetInterval(game.fall, stats.fallPeriod)
|
||||
} else {
|
||||
this.generate()
|
||||
}
|
||||
@ -74,7 +74,7 @@ let game = {
|
||||
playfield.piece.onLockDown = game.lockDown
|
||||
|
||||
if (playfield.piece.canMove(TRANSLATION.NONE)) {
|
||||
scheduler.setInterval(game.fall, stats.fallPeriod)
|
||||
scheduler.resetInterval(game.fall, stats.fallPeriod)
|
||||
} else {
|
||||
game.over() // block out
|
||||
}
|
||||
@ -216,8 +216,8 @@ function onkeydown(event) {
|
||||
actionsQueue.unshift(action)
|
||||
scheduler.clearTimeout(repeat)
|
||||
scheduler.clearInterval(autorepeat)
|
||||
if (action == playerActions.softDrop) scheduler.setInterval(autorepeat, settings.fallPeriod / 20)
|
||||
else scheduler.setTimeout(repeat, settings.dasDelay)
|
||||
if (action == playerActions.softDrop) scheduler.resetInterval(autorepeat, settings.fallPeriod / 20)
|
||||
else scheduler.resetTimeout(repeat, settings.dasDelay)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,7 +226,7 @@ function onkeydown(event) {
|
||||
function repeat() {
|
||||
if (actionsQueue.length) {
|
||||
actionsQueue[0]()
|
||||
scheduler.setInterval(autorepeat, settings.arrDelay)
|
||||
scheduler.resetInterval(autorepeat, settings.arrDelay)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ class Tetromino extends THREE.Group {
|
||||
} else if (translation == TRANSLATION.DOWN) {
|
||||
this.locked = true
|
||||
if (!scheduler.timeoutTasks.has(this.onLockDown))
|
||||
scheduler.setTimeout(this.onLockDown, this.lockDelay)
|
||||
scheduler.resetTimeout(this.onLockDown, this.lockDelay)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,11 @@ class Scheduler {
|
||||
}
|
||||
}
|
||||
|
||||
resetInterval(func, delay, ...args) {
|
||||
this.clearInterval(func)
|
||||
this.setInterval(func, delay, ...args)
|
||||
}
|
||||
|
||||
setTimeout(func, delay, ...args) {
|
||||
this.timeoutTasks.set(func, window.setTimeout(func, delay, ...args))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user