diff options
-rw-r--r-- | assets/ambient.wav | bin | 0 -> 40219224 bytes | |||
-rw-r--r-- | level.go | 32 | ||||
-rw-r--r-- | main.go | 27 |
3 files changed, 40 insertions, 19 deletions
diff --git a/assets/ambient.wav b/assets/ambient.wav Binary files differnew file mode 100644 index 0000000..3d1ced9 --- /dev/null +++ b/assets/ambient.wav @@ -102,22 +102,22 @@ func StartLevel4(g *Game) { g.ClearAll() tilemap := NewTilemap([][]int{ { - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 6, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, + 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, + 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, + 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 0, }, }, 25) @@ -33,6 +33,7 @@ const ( exitTransitionWeight = 0.9 ghostAlpha = 0.5 hightlightBorder = 2 + audioFadeIn = 0.999 sampleRate = 44100 ) @@ -57,6 +58,9 @@ var ( //go:embed assets/start.wav startWav_src []byte + + //go:embed assets/ambient.wav + ambientWav_src []byte ) var ( @@ -87,6 +91,7 @@ type AudioPlayer struct { rewindAudio *audio.Player stopAudio *audio.Player startAudio *audio.Player + ambientAudio *audio.Player } type Game struct { @@ -209,6 +214,7 @@ func (g *Game) Init() { g.ResetAll() StartLevel1(g) + g.audioPlayer.ambientAudio.SetVolume(0) ebiten.SetWindowSize(screenWidth*2, screenHeight*2) @@ -222,6 +228,16 @@ func (g *Game) Init() { func (g *Game) Update() error { g.time += 1 + + if g.state == IN_GAME || g.state == PLACING { + if ! g.audioPlayer.ambientAudio.IsPlaying() { + g.audioPlayer.ambientAudio.Play() + } + volume := g.audioPlayer.ambientAudio.Volume() + volume = 1-((1-volume)*audioFadeIn) + g.audioPlayer.ambientAudio.SetVolume(volume) + } + if g.state == IN_GAME { if inpututil.IsKeyJustPressed(ebiten.KeyR) { g.SetReversing() @@ -443,7 +459,7 @@ func (g *Game) EndLevel() { if g.state == IN_GAME { g.state = END g.TransitionState() - } + } if g.state == PLACING { g.ResetPlayerAi() } @@ -473,6 +489,7 @@ func (g *Game) SetReversing() { g.player.alpha = 1.0 g.audioPlayer.rewindAudio.Rewind() g.audioPlayer.rewindAudio.Play() + g.audioPlayer.ambientAudio.Pause() } func (g *Game) StopRewinding() { @@ -481,6 +498,7 @@ func (g *Game) StopRewinding() { g.audioPlayer.rewindAudio.Pause() g.audioPlayer.startAudio.Rewind() g.audioPlayer.startAudio.Play() + g.audioPlayer.ambientAudio.Play() } } @@ -520,6 +538,11 @@ func (g *Game) LoadAudio() { g.audioPlayer.rewindAudio = loadAudio(rewindWav_src, g.audioPlayer.audioContext) g.audioPlayer.stopAudio = loadAudio(stopWav_src, g.audioPlayer.audioContext) g.audioPlayer.startAudio = loadAudio(startWav_src, g.audioPlayer.audioContext) + g.audioPlayer.ambientAudio = loadAudio(ambientWav_src, g.audioPlayer.audioContext) + + if g.audioPlayer.ambientAudio == nil { + fmt.Printf("AUDIO NUL") + } } func (g *Game) LoadImages() { @@ -537,13 +560,11 @@ func (g *Game) LoadImages() { } tilesImage = ebiten.NewImageFromImage(img) - } func main() { LoadShaders() - ebiten.SetWindowTitle("Hello, World!") game := &Game{} game.LoadAudio() |