Skip to content

Commit

Permalink
comment out unreachable code
Browse files Browse the repository at this point in the history
  • Loading branch information
okwme committed Aug 12, 2024
1 parent 9336911 commit 8811ae8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
4 changes: 2 additions & 2 deletions dist/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions src/anybody.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ export class Anybody extends EventEmitter {
if (this.handledGameOver) return
this.handledGameOver = true
this.gameoverTickerX = 0
this.sound?.playGameOver({ won }) // TDDO: improve audio
if (this.level !== 0) {
this.sound?.playGameOver({ won }) // TDDO: improve audio
}
this.gameOver = true
this.won = won
if (this.level !== 0 && !this.won) {
Expand Down Expand Up @@ -487,12 +489,15 @@ export class Anybody extends EventEmitter {
this.setOptions(options)
}
this.clearValues()
if (this.level !== this.lastLevel && this.level !== 1) {
if (this.level !== this.lastLevel && this.level !== 1 && this.level !== 0) {
this.sound?.stop()
this.sound?.playStart()
this.sound?.setSong()
this.sound?.resume()
}
if (this.sound?.playbackRate !== 'normal') {
this.sound?.setPlaybackRate('normal')
}
this.init()
this.draw()
if (beginPaused) {
Expand Down Expand Up @@ -526,12 +531,13 @@ export class Anybody extends EventEmitter {

this.emit('paused', newPauseState)
if (newPauseState) {
if (!mute) this.sound?.pause()
if (!mute) {
this.sound?.pause()
}
} else {
console.log('resume called')
console.log('mute:' + mute)
console.log('this.sound:' + this.sound)
if (!mute) this.sound?.resume()
if (!mute) {
this.sound?.resume()
}
}
}

Expand Down
55 changes: 30 additions & 25 deletions src/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class Sound {
this.createPlayer()
window.addEventListener('keydown', this.handleKeyDown)
this.setSong()
this.playbackRate = 'normal'
}

async prepareForPlayback() {
Expand Down Expand Up @@ -120,13 +121,14 @@ export default class Sound {
this.missilePanner.pan.value = -PAN_RANGE / 2
let player
if (this.anybody.sfx === 'space') {
console.log({ vectorMagnitude })
const playbackRate =
vectorMagnitude < 666_666 ? 3 : vectorMagnitude < 1_333_332 ? 2 : 1
player = await this.playOneShot(bottlerocket2, -24, {
player = await this.playOneShot(bottlerocket2, -34, {
playbackRate
})
} else {
player = await this.playOneShot(bubble, -26, {
player = await this.playOneShot(bubble, -36, {
playbackRate: random([1, 0.9, 1.3])
})
}
Expand Down Expand Up @@ -184,30 +186,33 @@ export default class Sound {
}
}

// TODO: this explodes whenever you reset quickly
async setPlaybackRate(speed = 'normal') {
// prepare playback
this.prepareForPlayback()

// reset audio player
this.stop()

// speed up the voices
const playbackRate =
speed == 'normal' ? 1 : this.currentSong?.gameoverSpeed || 2

// set new gameover playback rate
this.player.playbackRate = playbackRate

// speed up the BPM w ramp
Tone.getTransport().bpm.rampTo(
(Tone.getTransport().bpm.value *= playbackRate),
0.5
)

// restart
this.loop?.start()
this.player.start()
Tone.getTransport().start('+0', 0)
this.playbackRate = speed
return
// // prepare playback
// this.prepareForPlayback()

// // reset audio player
// this.stop()

// // speed up the voices
// const playbackRate =
// speed == 'normal' ? 1 : this.currentSong?.gameoverSpeed || 2

// // set new gameover playback rate
// this.player.playbackRate = playbackRate

// // speed up the BPM w ramp
// Tone.getTransport().bpm.rampTo(
// (Tone.getTransport().bpm.value *= playbackRate),
// 0.5
// )

// // restart
// this.loop?.start()
// this.player.start()
// Tone.getTransport().start('+0', 0)
}

async playGameOver({ win }) {
Expand Down
3 changes: 3 additions & 0 deletions src/visuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ export const Visuals = {
this.level++
this.restart(null, false)
} else {
if (this.sound?.playbackRate !== 'normal') {
this.sound?.setPlaybackRate('normal')
}
this.drawStatsScreen()
}
}
Expand Down

0 comments on commit 8811ae8

Please sign in to comment.