|
|
|
@ -6,10 +6,12 @@ import (
|
|
|
|
|
"image"
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
|
|
_ "image/png"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/audio"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/audio/vorbis"
|
|
|
|
|
_ "image/png"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/audio/wav"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed image sound
|
|
|
|
@ -21,8 +23,12 @@ var ImgPlayer = LoadImage("image/player.png")
|
|
|
|
|
|
|
|
|
|
const sampleRate = 44100
|
|
|
|
|
|
|
|
|
|
var audioContext = audio.NewContext(sampleRate)
|
|
|
|
|
var SoundMusic = LoadOGG(audioContext, "sound/an_individual_who_fights_on_roads.ogg", true)
|
|
|
|
|
var (
|
|
|
|
|
audioContext = audio.NewContext(sampleRate)
|
|
|
|
|
SoundHitP1 = LoadWAV(audioContext, "sound/hit.wav")
|
|
|
|
|
SoundHitP2 = LoadWAV(audioContext, "sound/hit.wav")
|
|
|
|
|
SoundMusic = LoadOGG(audioContext, "sound/an_individual_who_fights_on_roads.ogg", true)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func LoadImage(p string) *ebiten.Image {
|
|
|
|
|
f, err := FS.Open(p)
|
|
|
|
@ -47,6 +53,33 @@ func LoadBytes(p string) []byte {
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LoadWAV(context *audio.Context, p string) *audio.Player {
|
|
|
|
|
f, err := FS.Open(p)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
stream, err := wav.DecodeWithSampleRate(sampleRate, f)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
player, err := context.NewPlayer(stream)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Workaround to prevent delays when playing for the first time.
|
|
|
|
|
player.SetVolume(0)
|
|
|
|
|
player.Play()
|
|
|
|
|
player.Pause()
|
|
|
|
|
player.Rewind()
|
|
|
|
|
player.SetVolume(1)
|
|
|
|
|
|
|
|
|
|
return player
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LoadOGG(context *audio.Context, p string, loop bool) *audio.Player {
|
|
|
|
|
b := LoadBytes(p)
|
|
|
|
|
|
|
|
|
|