enhancements
This commit is contained in:
parent
69c16647cf
commit
f096b13c65
34
app.js
34
app.js
@ -316,7 +316,7 @@ function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
settingsDialog.onclose = newGame
|
settingsDialog.onclose = newGame
|
||||||
showSettings()
|
pause()
|
||||||
}
|
}
|
||||||
startDialog.onclose = init
|
startDialog.onclose = init
|
||||||
|
|
||||||
@ -340,22 +340,19 @@ function draw() {
|
|||||||
batterySprite.draw()
|
batterySprite.draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSettings() {
|
window.onblur = pause
|
||||||
pause()
|
|
||||||
settingsDialog.showModal()
|
|
||||||
}
|
|
||||||
window.onblur = showSettings
|
|
||||||
|
|
||||||
function pause() {
|
function pause() {
|
||||||
Tone.Transport.pause()
|
Tone.Transport.pause()
|
||||||
playing = false
|
playing = false
|
||||||
|
settingsDialog.showModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
settingsButton.onclick = showSettings
|
settingsButton.onclick = pause
|
||||||
|
|
||||||
keyMapInput.onclick = keyMapInput.onkeyup = function(event) {
|
keyMapInput.onclick = keyMapInput.onkeyup = function(event) {
|
||||||
let cursorPosition = keyMapInput.selectionEnd
|
let cursorPosition = keyMapInput.selectionEnd
|
||||||
if ((event.key == "ArrowRight" && cursorPosition <= keyMapInput.value.length) || cursorPosition == 0) {
|
if (cursorPosition == 0 || (event.key == "ArrowRight" && cursorPosition <= keyMapInput.value.length)) {
|
||||||
keyMapInput.setSelectionRange(cursorPosition, cursorPosition+1)
|
keyMapInput.setSelectionRange(cursorPosition, cursorPosition+1)
|
||||||
} else {
|
} else {
|
||||||
keyMapInput.setSelectionRange(cursorPosition-1, cursorPosition)
|
keyMapInput.setSelectionRange(cursorPosition-1, cursorPosition)
|
||||||
@ -439,7 +436,7 @@ let midiSong
|
|||||||
let noteSprites = []
|
let noteSprites = []
|
||||||
let explosionSprites = []
|
let explosionSprites = []
|
||||||
let health
|
let health
|
||||||
function nextLevel(time=0) {
|
function nextLevel(time=Tone.Transport.seconds) {
|
||||||
Tone.Transport.pause(time)
|
Tone.Transport.pause(time)
|
||||||
level++
|
level++
|
||||||
midiSong = Midi.fromUrl(`midi/${level}.mid`).then((midi) => {
|
midiSong = Midi.fromUrl(`midi/${level}.mid`).then((midi) => {
|
||||||
@ -478,17 +475,24 @@ function resume() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.onkeydown = function(event) {
|
document.onkeydown = function(event) {
|
||||||
if (playing && keyMap.includes(event.key)) {
|
if (event.altKey || event.ctrlKey) return
|
||||||
event.preventDefault()
|
|
||||||
let note = FIRST_NOTE + keyMap.indexOf(event.key)
|
let keyIndex = keyMap.indexOf(event.key.toLowerCase())
|
||||||
|
if (keyIndex >= 0) {
|
||||||
|
if (event.target != keyMapInput) event.preventDefault()
|
||||||
|
let note = FIRST_NOTE + keyIndex
|
||||||
shoot(note)
|
shoot(note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.onkeyup = function(event) {
|
document.onkeyup = function(event) {
|
||||||
if (playing && keyMap.includes(event.key)) {
|
if (event.altKey || event.ctrlKey) return
|
||||||
event.preventDefault()
|
if (event.key =="Escape") pause()
|
||||||
let note = FIRST_NOTE + keyMap.indexOf(event.key)
|
|
||||||
|
let keyIndex = keyMap.indexOf(event.key.toLowerCase())
|
||||||
|
if (keyIndex >= 0) {
|
||||||
|
if (event.target != keyMapInput) event.preventDefault()
|
||||||
|
let note = FIRST_NOTE + keyIndex
|
||||||
stopShoot(note)
|
stopShoot(note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user