Pause/unpause sound added. Minor audio tweaks. Cleanup.

This commit is contained in:
2024-11-11 17:25:33 -05:00
parent 7b08eadd27
commit 8a1194eca3
5 changed files with 21 additions and 48 deletions

View File

@@ -8,6 +8,7 @@ import (
"mover/gamedata"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/audio"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text"
)
@@ -20,6 +21,7 @@ type StartScreen struct {
targetreached bool
audioplayed bool
cycle int
audioplayer *audio.Player
}
func NewStartScreen() *StartScreen {
@@ -39,11 +41,14 @@ func (s *StartScreen) Update() error {
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) ||
ebiten.IsStandardGamepadButtonPressed(0, ebiten.StandardGamepadButtonCenterRight) {
s.eHandler[EventCompleted]()
if s.audioplayer.IsPlaying() {
s.audioplayer.Close()
}
}
if !s.audioplayed {
player := audioContext.NewPlayerFromBytes(assets.Survive)
player.Play()
s.audioplayer = audioContext.NewPlayerFromBytes(assets.Survive)
s.audioplayer.Play()
s.audioplayed = true
}