Support muting audio

This commit is contained in:
Trevor Slocum 2021-10-27 21:03:59 -07:00
parent 5f011b53ba
commit 41275ad3c1
1 changed files with 14 additions and 3 deletions

17
game.go
View File

@ -141,8 +141,6 @@ func NewGame() (*game, error) {
g.audioContext = audio.NewContext(sampleRate)
ebiten.SetCursorShape(ebiten.CursorShapeCrosshair)
err := g.loadAssets()
if err != nil {
return nil, err
@ -283,6 +281,8 @@ func (g *game) reset() error {
g.gameOverTime = time.Time{}
g.gameWon = false
g.updateCursor()
g.forceColorScale = -1
g.player.hasTorch = true
@ -328,11 +328,12 @@ func (g *game) Layout(outsideWidth, outsideHeight int) (int, int) {
}
func (g *game) updateCursor() {
if g.activeGamepad == -1 || g.gameWon {
if g.activeGamepad != -1 || g.gameWon {
ebiten.SetCursorMode(ebiten.CursorModeHidden)
return
}
ebiten.SetCursorMode(ebiten.CursorModeVisible)
ebiten.SetCursorShape(ebiten.CursorShapeCrosshair)
}
// Update reads current user input and updates the game state.
@ -736,6 +737,14 @@ UPDATEPROJECTILES:
g.flashMessage("GOD MODE DEACTIVATED")
}
}
if inpututil.IsKeyJustPressed(ebiten.KeyM) {
g.muteAudio = !g.muteAudio
if g.muteAudio {
g.flashMessage("AUDIO MUTED")
} else {
g.flashMessage("AUDIO UNMUTED")
}
}
if inpututil.IsKeyJustPressed(ebiten.KeyN) {
g.noclipMode = !g.noclipMode
if g.noclipMode {
@ -1253,6 +1262,8 @@ func (g *game) showWinScreen() {
g.updateCursor()
g.player.health = 0
g.player.garlicUntil = time.Time{}
g.player.holyWaterUntil = time.Time{}
g.level = newWinLevel(g.player)