play wall sound only if player action succeded previously
This commit is contained in:
parent
ebb9f4810b
commit
8773e65885
31
js/app.js
31
js/app.js
@ -5,6 +5,7 @@ let holdQueue = new MinoesTable("holdTable")
|
|||||||
let matrix = new Matrix()
|
let matrix = new Matrix()
|
||||||
let nextQueue = new NextQueue()
|
let nextQueue = new NextQueue()
|
||||||
let playing = false
|
let playing = false
|
||||||
|
let lastActionSucceded = true
|
||||||
let favicon
|
let favicon
|
||||||
|
|
||||||
window.onload = function(event) {
|
window.onload = function(event) {
|
||||||
@ -94,6 +95,7 @@ function ticktack() {
|
|||||||
|
|
||||||
function generate(piece) {
|
function generate(piece) {
|
||||||
matrix.piece = piece || nextQueue.shift()
|
matrix.piece = piece || nextQueue.shift()
|
||||||
|
lastActionSucceded = true
|
||||||
favicon.href = matrix.piece.favicon_href
|
favicon.href = matrix.piece.favicon_href
|
||||||
|
|
||||||
if (matrix.piece.canMove(TRANSLATION.NONE)) {
|
if (matrix.piece.canMove(TRANSLATION.NONE)) {
|
||||||
@ -112,23 +114,15 @@ let playerActions = {
|
|||||||
|
|
||||||
rotateCounterclockwise: () => matrix.piece.rotate(ROTATION.CCW),
|
rotateCounterclockwise: () => matrix.piece.rotate(ROTATION.CCW),
|
||||||
|
|
||||||
softDrop: function() {
|
softDrop: () => matrix.piece.move(TRANSLATION.DOWN) && ++stats.score,
|
||||||
if (matrix.piece.move(TRANSLATION.DOWN)) {
|
|
||||||
stats.score++
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
hardDrop: function() {
|
hardDrop: function() {
|
||||||
scheduler.clearTimeout(lockDown)
|
scheduler.clearTimeout(lockDown)
|
||||||
playSound(hardDropSound)
|
playSound(hardDropSound)
|
||||||
while (matrix.piece.move(TRANSLATION.DOWN, ROTATION.NONE, true)) stats.score +=2
|
while (matrix.piece.move(TRANSLATION.DOWN, ROTATION.NONE, true)) stats.score +=2
|
||||||
// wallSound.currentTime = 0
|
|
||||||
// wallSound.pause()
|
|
||||||
matrix.table.classList.add("hard-dropped-table-animation")
|
matrix.table.classList.add("hard-dropped-table-animation")
|
||||||
lockDown()
|
lockDown()
|
||||||
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
hold: function() {
|
hold: function() {
|
||||||
@ -164,7 +158,12 @@ function onkeydown(event) {
|
|||||||
if (!pressedKeys.has(event.key)) {
|
if (!pressedKeys.has(event.key)) {
|
||||||
pressedKeys.add(event.key)
|
pressedKeys.add(event.key)
|
||||||
action = settings.keyBind[event.key]
|
action = settings.keyBind[event.key]
|
||||||
action()
|
if (action()) {
|
||||||
|
lastActionSucceded = true
|
||||||
|
} else if (lastActionSucceded) {
|
||||||
|
wallSound.play()
|
||||||
|
lastActionSucceded = false
|
||||||
|
}
|
||||||
if (REPEATABLE_ACTIONS.includes(action)) {
|
if (REPEATABLE_ACTIONS.includes(action)) {
|
||||||
actionsQueue.unshift(action)
|
actionsQueue.unshift(action)
|
||||||
scheduler.clearTimeout(repeat)
|
scheduler.clearTimeout(repeat)
|
||||||
@ -186,11 +185,15 @@ function repeat() {
|
|||||||
|
|
||||||
function autorepeat() {
|
function autorepeat() {
|
||||||
if (actionsQueue.length) {
|
if (actionsQueue.length) {
|
||||||
actionsQueue[0]()
|
if (actionsQueue[0]()) {
|
||||||
} else {
|
lastActionSucceded = true
|
||||||
scheduler.clearInterval(autorepeat)
|
} else if (lastActionSucceded) {
|
||||||
|
wallSound.play()
|
||||||
|
lastActionSucceded = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else scheduler.clearInterval(autorepeat)
|
||||||
|
}
|
||||||
|
|
||||||
function onkeyup(event) {
|
function onkeyup(event) {
|
||||||
if (event.key in settings.keyBind) {
|
if (event.key in settings.keyBind) {
|
||||||
|
@ -103,17 +103,32 @@ class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setInterval(func, delay, ...args) {
|
setInterval(func, delay, ...args) {
|
||||||
|
if (this.intervalTasks.has(func)) {
|
||||||
|
console.warn(`$func already in intervalTasks`)
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
this.intervalTasks.set(func, window.setInterval(func, delay, ...args))
|
this.intervalTasks.set(func, window.setInterval(func, delay, ...args))
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(func, delay, ...args) {
|
setTimeout(func, delay, ...args) {
|
||||||
|
if (this.timeoutTasks.has(func)) {
|
||||||
|
console.warn(`$func already in timeoutTasks`)
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
this.timeoutTasks.set(func, window.setTimeout(func, delay, ...args))
|
this.timeoutTasks.set(func, window.setTimeout(func, delay, ...args))
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInterval(func) {
|
clearInterval(func) {
|
||||||
if (this.intervalTasks.has(func)) {
|
if (this.intervalTasks.has(func)) {
|
||||||
window.clearInterval(this.intervalTasks.get(func))
|
window.clearInterval(this.intervalTasks.get(func))
|
||||||
this.intervalTasks.delete(func)
|
this.intervalTasks.delete(func)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +136,9 @@ class Scheduler {
|
|||||||
if (this.timeoutTasks.has(func)) {
|
if (this.timeoutTasks.has(func)) {
|
||||||
window.clearTimeout(this.timeoutTasks.get(func))
|
window.clearTimeout(this.timeoutTasks.get(func))
|
||||||
this.timeoutTasks.delete(func)
|
this.timeoutTasks.delete(func)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,7 +350,6 @@ class Tetromino {
|
|||||||
matrix.drawPiece()
|
matrix.drawPiece()
|
||||||
return true
|
return true
|
||||||
} else if (!hardDropped) {
|
} else if (!hardDropped) {
|
||||||
wallSound.play()
|
|
||||||
if (translation == TRANSLATION.DOWN) {
|
if (translation == TRANSLATION.DOWN) {
|
||||||
this.locked = true
|
this.locked = true
|
||||||
if (!scheduler.timeoutTasks.has(lockDown))
|
if (!scheduler.timeoutTasks.has(lockDown))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user