Added music and sfx.

This commit is contained in:
2024-11-11 14:07:02 -05:00
parent 56d1f62020
commit 658ae73c9b
15 changed files with 207 additions and 73 deletions

View File

@@ -3,6 +3,7 @@ package screens
import (
"image/color"
"math"
"mover/assets"
"mover/fonts"
"mover/gamedata"
@@ -17,6 +18,8 @@ type StartScreen struct {
target gamedata.Coordinates
current gamedata.Coordinates
targetreached bool
audioplayed bool
cycle int
}
func NewStartScreen() *StartScreen {
@@ -25,6 +28,8 @@ func NewStartScreen() *StartScreen {
target: gamedata.Coordinates{X: 640/2 - 150, Y: 480 / 2},
current: gamedata.Coordinates{X: 640/2 - 150, Y: -100},
targetreached: false,
cycle: 0,
audioplayed: false,
}
return s
}
@@ -36,13 +41,24 @@ func (s *StartScreen) Update() error {
s.eHandler[EventCompleted]()
}
s.current.X += (s.target.X - s.current.X) / 8
s.current.Y += (s.target.Y - s.current.Y) / 8
if !s.audioplayed {
player := audioContext.NewPlayerFromBytes(assets.Survive)
player.Play()
s.audioplayed = true
}
if !s.targetreached {
s.current.X += (s.target.X - s.current.X) / 8
s.current.Y += (s.target.Y - s.current.Y) / 8
} else {
s.current.Y += 0.5 * math.Sin(float64(s.cycle)/(math.Pi*8))
}
if math.Abs(s.current.Y-s.target.Y) < 1 && !s.targetreached {
s.targetreached = true
}
s.cycle++
return nil
}