Play Him Off, Keyboard Cat
This commit is contained in:
parent
0a09ad4e24
commit
90df10e141
120
app.js
120
app.js
@ -409,16 +409,6 @@ midiSelect.oninput = () => {
|
|||||||
window.localStorage.midiKeyboard = midiKeyboard
|
window.localStorage.midiKeyboard = midiKeyboard
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMIDIMessage(event) {
|
|
||||||
let [code, note, velocity] = event.data
|
|
||||||
|
|
||||||
if (144 <= code && code <= 159 && cannonSprites[note]) {
|
|
||||||
cannonSprites[note].shooting = true
|
|
||||||
} else if (128 <= code && code <= 143 && cannonSprites[note]) {
|
|
||||||
cannonSprites[note].shooting = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
volRange.oninput = function(event) {
|
volRange.oninput = function(event) {
|
||||||
volume.gain.linearRampToValueAtTime(volRange.value, audioCtx.currentTime)
|
volume.gain.linearRampToValueAtTime(volRange.value, audioCtx.currentTime)
|
||||||
}
|
}
|
||||||
@ -486,6 +476,39 @@ function resume() {
|
|||||||
Tone.Transport.start()
|
Tone.Transport.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.onkeydown = function(event) {
|
||||||
|
if (playing && keyMap.includes(event.key)) {
|
||||||
|
event.preventDefault()
|
||||||
|
let note = FIRST_NOTE + keyMap.indexOf(event.key)
|
||||||
|
shoot(note)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.onkeyup = function(event) {
|
||||||
|
if (playing && keyMap.includes(event.key)) {
|
||||||
|
event.preventDefault()
|
||||||
|
let note = FIRST_NOTE + keyMap.indexOf(event.key)
|
||||||
|
stopShoot(note)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMIDIMessage(event) {
|
||||||
|
let [code, note, velocity] = event.data
|
||||||
|
if (144 <= code && code <= 159 && cannonSprites[note]) {
|
||||||
|
shoot(note)
|
||||||
|
} else if (128 <= code && code <= 143 && cannonSprites[note]) {
|
||||||
|
stopShoot(note)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shoot(note) {
|
||||||
|
cannonSprites[note].shooting = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopShoot(note) {
|
||||||
|
cannonSprites[note].shooting = false
|
||||||
|
}
|
||||||
|
|
||||||
function update(time) {
|
function update(time) {
|
||||||
noteSprites.filter(noteSprite => !noteSprite.shot).forEach(noteSprite => {
|
noteSprites.filter(noteSprite => !noteSprite.shot).forEach(noteSprite => {
|
||||||
noteSprite.y += STEP
|
noteSprite.y += STEP
|
||||||
@ -508,10 +531,11 @@ function update(time) {
|
|||||||
|
|
||||||
cannonSprites.filter(cannonSprite => cannonSprite.shooting).forEach(cannonSprite => {
|
cannonSprites.filter(cannonSprite => cannonSprite.shooting).forEach(cannonSprite => {
|
||||||
let noteSprite = noteSprites.find(noteSprite => noteSprite.note == cannonSprite.note)
|
let noteSprite = noteSprites.find(noteSprite => noteSprite.note == cannonSprite.note)
|
||||||
|
cannonSprite.impactY = noteSprite?.y || 0
|
||||||
if (noteSprite) {
|
if (noteSprite) {
|
||||||
|
cannonSprite.impactY = noteSprite.y
|
||||||
if (!noteSprite.shot) {
|
if (!noteSprite.shot) {
|
||||||
playNote(noteSprite.note, noteSprite.velocity, noteSprite.duration, time)
|
playNote(noteSprite.note, noteSprite.velocity, noteSprite.duration, time)
|
||||||
cannonSprite.impactY = noteSprite.y
|
|
||||||
noteSprite.shot = true
|
noteSprite.shot = true
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
noteSprites.remove(noteSprite)
|
noteSprites.remove(noteSprite)
|
||||||
@ -526,39 +550,6 @@ function update(time) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function victory(time) {
|
|
||||||
canvas.classList = "victory"
|
|
||||||
victoryDialog.showModal()
|
|
||||||
}
|
|
||||||
|
|
||||||
function gameOver(time) {
|
|
||||||
playing = false
|
|
||||||
|
|
||||||
cannonSprites.forEach(cannonSprite => {
|
|
||||||
let explosionSprite = cannonSprite.explose()
|
|
||||||
explosionSprites.push(explosionSprite)
|
|
||||||
explosionSprite.play().then(() => explosionSprites.remove(explosionSprite))
|
|
||||||
})
|
|
||||||
|
|
||||||
noteSprites.forEach(noteSprite => {
|
|
||||||
let explosionSprite = noteSprite.explose()
|
|
||||||
explosionSprites.push(explosionSprite)
|
|
||||||
explosionSprite.play().then(() => explosionSprites.remove(explosionSprite))
|
|
||||||
})
|
|
||||||
noteSprites = []
|
|
||||||
playNoise(0.7, 400, 2, time)
|
|
||||||
|
|
||||||
Tone.Transport.clear(updateTaskId)
|
|
||||||
Tone.Transport.scheduleOnce((time) => {
|
|
||||||
Tone.Transport.stop(time)
|
|
||||||
}, time + 0.1)
|
|
||||||
gameOverDialog.showModal()
|
|
||||||
}
|
|
||||||
|
|
||||||
victoryDialog.onclose = gameOverDialog.onclose = function() {
|
|
||||||
document.location = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
function playNote(note, velocity=0.7, duration=0, time=0) {
|
function playNote(note, velocity=0.7, duration=0, time=0) {
|
||||||
if(oscillators[note]) return
|
if(oscillators[note]) return
|
||||||
|
|
||||||
@ -617,18 +608,35 @@ function playNoise(startGain=0.5, bandHz=1000, duration, time) {
|
|||||||
noise.stop(time + duration)
|
noise.stop(time + duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
document.onkeydown = function(event) {
|
function victory(time) {
|
||||||
if (playing && keyMap.includes(event.key)) {
|
canvas.classList = "victory"
|
||||||
event.preventDefault()
|
victoryDialog.showModal()
|
||||||
let note = FIRST_NOTE + keyMap.indexOf(event.key)
|
|
||||||
cannonSprites[note].shooting = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.onkeyup = function(event) {
|
function gameOver(time) {
|
||||||
if (playing && keyMap.includes(event.key)) {
|
playing = false
|
||||||
event.preventDefault()
|
|
||||||
let note = FIRST_NOTE + keyMap.indexOf(event.key)
|
cannonSprites.forEach(cannonSprite => {
|
||||||
cannonSprites[note].shooting = false
|
let explosionSprite = cannonSprite.explose()
|
||||||
}
|
explosionSprites.push(explosionSprite)
|
||||||
|
explosionSprite.play().then(() => explosionSprites.remove(explosionSprite))
|
||||||
|
})
|
||||||
|
|
||||||
|
noteSprites.forEach(noteSprite => {
|
||||||
|
let explosionSprite = noteSprite.explose()
|
||||||
|
explosionSprites.push(explosionSprite)
|
||||||
|
explosionSprite.play().then(() => explosionSprites.remove(explosionSprite))
|
||||||
|
})
|
||||||
|
noteSprites = []
|
||||||
|
playNoise(0.7, 400, 2, time)
|
||||||
|
|
||||||
|
Tone.Transport.clear(updateTaskId)
|
||||||
|
Tone.Transport.scheduleOnce((time) => {
|
||||||
|
Tone.Transport.stop(time)
|
||||||
|
}, time + 0.1)
|
||||||
|
gameOverDialog.showModal()
|
||||||
|
}
|
||||||
|
|
||||||
|
victoryDialog.onclose = gameOverDialog.onclose = function() {
|
||||||
|
document.location = ""
|
||||||
}
|
}
|
BIN
midi/1.mid
BIN
midi/1.mid
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user