added mp3 functionality
fixed bug where last move on correct square didn't register
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/audio"
|
||||
"github.com/hajimehoshi/ebiten/v2/audio/mp3"
|
||||
"github.com/hajimehoshi/ebiten/v2/audio/wav"
|
||||
)
|
||||
|
||||
@@ -30,7 +31,7 @@ func loadTracksForSong(sng int) map[int]*audio.Player {
|
||||
|
||||
var SFXLibrary = map[string]*audio.Player{
|
||||
"newLevel": LoadWavAudioFile("audio/portal2.wav", false),
|
||||
"colourMatch": LoadWavAudioFile("audio/portal.wav", false),
|
||||
"colourMatch": LoadMP3AudioFile("audio/portal.mp3", false),
|
||||
"gameOver": LoadWavAudioFile("audio/gameOver.wav", false),
|
||||
}
|
||||
|
||||
@@ -64,6 +65,36 @@ func LoadWavAudioFile(filePath string, loop bool) *audio.Player {
|
||||
|
||||
}
|
||||
|
||||
func LoadMP3AudioFile(filePath string, loop bool) *audio.Player {
|
||||
|
||||
audioData, err := fs.ReadFile(embeddedFiles, filePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
stream, err := mp3.DecodeWithSampleRate(sampleRate, bytes.NewReader(audioData))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to decode audio: %v", err)
|
||||
}
|
||||
|
||||
var player *audio.Player
|
||||
|
||||
if loop {
|
||||
lengthOfAudioData := int64(len(audioData))
|
||||
loopingStream := audio.NewInfiniteLoop(stream, lengthOfAudioData)
|
||||
player, err = audioContext.NewPlayer(loopingStream)
|
||||
|
||||
} else {
|
||||
player, err = audioContext.NewPlayer(stream)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return player
|
||||
|
||||
}
|
||||
|
||||
func SilenceSongTracks() {
|
||||
for _, song := range SongTracks {
|
||||
song.SetVolume(0)
|
||||
|
||||
Reference in New Issue
Block a user