Compare commits
2 Commits
baf6e66244
...
8773e65885
Author | SHA1 | Date | |
---|---|---|---|
8773e65885 | |||
ebb9f4810b |
@ -58,8 +58,7 @@
|
||||
</fieldset>
|
||||
<fieldset class="row g-2 mb-3 align-items-center text-center">
|
||||
<legend class="text-start">Interface</legend>
|
||||
<label for="sfxVolumeRange" class="col-2 col-form-label">Volume</label>
|
||||
<div class="col-4 d-flex align-items-baseline"><input id="sfxVolumeRange" class="form-range" type="range" min="0" max="1" step="any" value="0.7"></div>
|
||||
<label for="stylesheetSelect" class="col-2 col-form-label">Thème</label>
|
||||
<div class="col-4"><select name="stylesheet" id="stylesheetSelect" class="form-select" oninput="document.selectedStyleSheetSet=this.value">
|
||||
<option selected>Classique</option>
|
||||
<option>Minimal</option>
|
||||
@ -67,7 +66,8 @@
|
||||
<option>Électro</option>
|
||||
<option>Rétro</option>
|
||||
</select></div>
|
||||
<label for="stylesheetSelect" class="col-2 col-form-label">Thème</label>
|
||||
<div class="col-4 d-flex align-items-baseline"><input id="sfxVolumeRange" class="form-range" type="range" min="0" max="1" step="any" value="0.7"></div>
|
||||
<label for="sfxVolumeRange" class="col-2 col-form-label">Volume</label>
|
||||
</fieldset>
|
||||
<fieldset class="row g-2 mb-3 align-items-center text-center">
|
||||
<legend class="text-start">Partie</legend>
|
||||
@ -213,7 +213,7 @@
|
||||
<audio id="wallSound" src="sounds/808K_A.wav" preload="auto" type="audio/wav"></audio>
|
||||
<audio id="hardDropSound" src="sounds/909S.wav" preload="auto" type="audio/wav"></audio>
|
||||
<audio id="lineClearSound" src="sounds/808COW.wav" preload="auto" type="audio/wav"></audio>
|
||||
<audio id="tSpinSound" src="sounds/909CHH.wav" preload="auto" type="audio/wav"></audio>
|
||||
<audio id="tSpinSound" src="sounds/78GUIR.wav" preload="auto" type="audio/wav"></audio>
|
||||
<audio id="quatuorSound" src="sounds/BRRDC1.wav" preload="auto" type="audio/wav"></audio>
|
||||
</span>
|
||||
|
||||
|
45
js/app.js
45
js/app.js
@ -1,10 +1,11 @@
|
||||
let scheduler = new Scheduler()
|
||||
let settings = new Settings()
|
||||
let stats = new Stats()
|
||||
let holdQueue = new MinoesTable("holdTable")
|
||||
let matrix = new Matrix()
|
||||
let nextQueue = new NextQueue()
|
||||
let playing = false
|
||||
let scheduler = new Scheduler()
|
||||
let settings = new Settings()
|
||||
let stats = new Stats()
|
||||
let holdQueue = new MinoesTable("holdTable")
|
||||
let matrix = new Matrix()
|
||||
let nextQueue = new NextQueue()
|
||||
let playing = false
|
||||
let lastActionSucceded = true
|
||||
let favicon
|
||||
|
||||
window.onload = function(event) {
|
||||
@ -94,6 +95,7 @@ function ticktack() {
|
||||
|
||||
function generate(piece) {
|
||||
matrix.piece = piece || nextQueue.shift()
|
||||
lastActionSucceded = true
|
||||
favicon.href = matrix.piece.favicon_href
|
||||
|
||||
if (matrix.piece.canMove(TRANSLATION.NONE)) {
|
||||
@ -112,23 +114,15 @@ let playerActions = {
|
||||
|
||||
rotateCounterclockwise: () => matrix.piece.rotate(ROTATION.CCW),
|
||||
|
||||
softDrop: function() {
|
||||
if (matrix.piece.move(TRANSLATION.DOWN)) {
|
||||
stats.score++
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
softDrop: () => matrix.piece.move(TRANSLATION.DOWN) && ++stats.score,
|
||||
|
||||
hardDrop: function() {
|
||||
scheduler.clearTimeout(lockDown)
|
||||
playSound(hardDropSound)
|
||||
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")
|
||||
lockDown()
|
||||
return true
|
||||
},
|
||||
|
||||
hold: function() {
|
||||
@ -164,7 +158,12 @@ function onkeydown(event) {
|
||||
if (!pressedKeys.has(event.key)) {
|
||||
pressedKeys.add(event.key)
|
||||
action = settings.keyBind[event.key]
|
||||
action()
|
||||
if (action()) {
|
||||
lastActionSucceded = true
|
||||
} else if (lastActionSucceded) {
|
||||
wallSound.play()
|
||||
lastActionSucceded = false
|
||||
}
|
||||
if (REPEATABLE_ACTIONS.includes(action)) {
|
||||
actionsQueue.unshift(action)
|
||||
scheduler.clearTimeout(repeat)
|
||||
@ -186,10 +185,14 @@ function repeat() {
|
||||
|
||||
function autorepeat() {
|
||||
if (actionsQueue.length) {
|
||||
actionsQueue[0]()
|
||||
} else {
|
||||
scheduler.clearInterval(autorepeat)
|
||||
if (actionsQueue[0]()) {
|
||||
lastActionSucceded = true
|
||||
} else if (lastActionSucceded) {
|
||||
wallSound.play()
|
||||
lastActionSucceded = false
|
||||
}
|
||||
}
|
||||
else scheduler.clearInterval(autorepeat)
|
||||
}
|
||||
|
||||
function onkeyup(event) {
|
||||
|
@ -103,17 +103,32 @@ class Scheduler {
|
||||
}
|
||||
|
||||
setInterval(func, delay, ...args) {
|
||||
this.intervalTasks.set(func, window.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))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(func, delay, ...args) {
|
||||
this.timeoutTasks.set(func, window.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))
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
clearInterval(func) {
|
||||
if (this.intervalTasks.has(func)) {
|
||||
window.clearInterval(this.intervalTasks.get(func))
|
||||
this.intervalTasks.delete(func)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +136,9 @@ class Scheduler {
|
||||
if (this.timeoutTasks.has(func)) {
|
||||
window.clearTimeout(this.timeoutTasks.get(func))
|
||||
this.timeoutTasks.delete(func)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -332,7 +350,6 @@ class Tetromino {
|
||||
matrix.drawPiece()
|
||||
return true
|
||||
} else if (!hardDropped) {
|
||||
wallSound.play()
|
||||
if (translation == TRANSLATION.DOWN) {
|
||||
this.locked = true
|
||||
if (!scheduler.timeoutTasks.has(lockDown))
|
||||
|
BIN
sounds/78GUIR.wav
Normal file
BIN
sounds/78GUIR.wav
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user